Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #186 from ckeditor/t/185
Browse files Browse the repository at this point in the history
Fix: Table rows will not be added on tab key press if the associated command is disabled. Closes #185.
  • Loading branch information
jodator committed May 6, 2019
2 parents 241f067 + e6cc3bc commit 00848a8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/tableediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,13 @@ export default class TableEditing extends Plugin {
const isLastRow = currentRowIndex === table.childCount - 1;

if ( isForward && isLastRow && isLastCellInRow ) {
editor.plugins.get( 'TableUtils' ).insertRows( table, { at: table.childCount } );
editor.execute( 'insertTableRowBelow' );

// Check if the command actually added a row. If `insertTableRowBelow` execution didn't add a row (because it was disabled
// or it got overwritten) do not change the selection.
if ( currentRowIndex === table.childCount - 1 ) {
return;
}
}

let cellToFocus;
Expand Down
16 changes: 16 additions & 0 deletions tests/tableediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,22 @@ describe( 'TableEditing', () => {
] ) );
} );

it( 'should not create another row and not move the caret if insertTableRowBelow command is disabled', () => {
setModelData( model, modelTable( [
[ '11', '12[]' ]
] ) );

const insertTableRowBelowCommand = editor.commands.get( 'insertTableRowBelow' );

insertTableRowBelowCommand.forceDisabled( 'test' );

editor.editing.view.document.fire( 'keydown', domEvtDataStub );

expect( formatTable( getModelData( model ) ) ).to.equal( formattedModelTable( [
[ '11', '12[]' ]
] ) );
} );

it( 'should move to the first cell of next row if on end of a row', () => {
setModelData( model, modelTable( [
[ '11', '12[]' ],
Expand Down

0 comments on commit 00848a8

Please sign in to comment.