Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I/6453: Shift+click should use anchor cell if there is any. #6730

Merged
merged 5 commits into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/ckeditor5-table/src/tableselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export default class TableSelection extends Plugin {
return;
}

const anchorCell = getTableCellsContainingSelection( editor.model.document.selection )[ 0 ];
const anchorCell = this.getAnchorCell() || getTableCellsContainingSelection( editor.model.document.selection )[ 0 ];

if ( !anchorCell ) {
return;
Expand Down
33 changes: 33 additions & 0 deletions packages/ckeditor5-table/tests/tableselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,39 @@ describe( 'table selection', () => {
expect( preventDefault.called ).to.equal( true );
} );

it( 'should use the anchor cell from the selection if possible', () => {
const preventDefault = sinon.spy();

const domEventDataMock = new DomEventData( view, {
shiftKey: true,
target: view.domConverter.mapViewToDom(
// figure > table > tbody > tr > td
viewDocument.getRoot().getChild( 0 ).getChild( 1 ).getChild( 0 ).getChild( 0 ).getChild( 2 )
),
preventDefault
} );

tableSelection.setCellSelection(
modelRoot.getNodeByPath( [ 0, 1, 0 ] ),
modelRoot.getNodeByPath( [ 0, 2, 1 ] )
);
assertSelectedCells( model, [
[ 0, 0, 0 ],
[ 1, 1, 0 ],
[ 1, 1, 0 ]
] );

viewDocument.fire( 'mousedown', domEventDataMock );

assertSelectedCells( model, [
[ 1, 1, 1 ],
[ 1, 1, 1 ],
[ 0, 0, 0 ]
] );

expect( preventDefault.called ).to.equal( true );
} );

it( 'should ignore `selectionChange` event when selecting cells', () => {
const consoleLog = sinon.stub( console, 'log' );
const preventDefault = sinon.spy();
Expand Down