From d2d2283b1b03f6453a77923732a51a471b30125a Mon Sep 17 00:00:00 2001 From: Kuba Niegowski Date: Tue, 23 Jun 2020 10:16:42 +0200 Subject: [PATCH 1/2] Table multi-cell selection should not be possible with the keystrokes when the TableSelection plugin is disabled. --- packages/ckeditor5-table/src/tablekeyboard.js | 4 ++-- .../ckeditor5-table/tests/tablekeyboard.js | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/ckeditor5-table/src/tablekeyboard.js b/packages/ckeditor5-table/src/tablekeyboard.js index 6fdf2680228..e5c5fb7c94f 100644 --- a/packages/ckeditor5-table/src/tablekeyboard.js +++ b/packages/ckeditor5-table/src/tablekeyboard.js @@ -468,9 +468,9 @@ export default class TableKeyboard extends Plugin { const cellToSelect = tableMap.find( cellInfo => cellInfo.row == row && cellInfo.column == column ).cell; const isForward = [ 'right', 'down' ].includes( direction ); + const tableSelection = this.editor.plugins.get( 'TableSelection' ); - if ( expandSelection ) { - const tableSelection = this.editor.plugins.get( 'TableSelection' ); + if ( expandSelection && tableSelection.isEnabled ) { const anchorCell = tableSelection.getAnchorCell() || focusCell; tableSelection.setCellSelection( anchorCell, cellToSelect ); diff --git a/packages/ckeditor5-table/tests/tablekeyboard.js b/packages/ckeditor5-table/tests/tablekeyboard.js index d718e6c7cf9..a1ef10c32ef 100644 --- a/packages/ckeditor5-table/tests/tablekeyboard.js +++ b/packages/ckeditor5-table/tests/tablekeyboard.js @@ -1277,6 +1277,30 @@ describe( 'TableKeyboard', () => { downArrowDomEvtDataStub.shiftKey = true; } ); + it( 'should not expand the selection if TableSelection plugin is disabled', () => { + editor.plugins.get( 'TableSelection' ).forceDisabled(); + + editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub ); + + assertEqualMarkup( getModelData( model ), modelTable( [ + [ '00', '01', '02' ], + [ '10[]', '11', '12' ], + [ '20', '21', '22' ] + ] ) ); + + editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub ); + + assertEqualMarkup( getModelData( model ), modelTable( [ + [ '00', '01', '02' ], + [ '10', '11', '12' ], + [ '[]20', '21', '22' ] + ] ) ); + + expect( tableSelection.getAnchorCell() ).to.be.null; + expect( tableSelection.getFocusCell() ).to.be.null; + expect( selection.rangeCount ).to.equal( 1 ); + } ); + it( 'should expand the selection to the cell on the left', () => { editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub ); From e1d36b4541ed2067cca895542548192ed3f1dc51 Mon Sep 17 00:00:00 2001 From: Maciej Date: Tue, 23 Jun 2020 11:16:30 +0200 Subject: [PATCH 2/2] Update packages/ckeditor5-table/tests/tablekeyboard.js. --- packages/ckeditor5-table/tests/tablekeyboard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ckeditor5-table/tests/tablekeyboard.js b/packages/ckeditor5-table/tests/tablekeyboard.js index a1ef10c32ef..6f53a0ab450 100644 --- a/packages/ckeditor5-table/tests/tablekeyboard.js +++ b/packages/ckeditor5-table/tests/tablekeyboard.js @@ -1277,7 +1277,7 @@ describe( 'TableKeyboard', () => { downArrowDomEvtDataStub.shiftKey = true; } ); - it( 'should not expand the selection if TableSelection plugin is disabled', () => { + it( 'should move to the cell below if TableSelection plugin is disabled', () => { editor.plugins.get( 'TableSelection' ).forceDisabled(); editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );