diff --git a/src/tableediting.js b/src/tableediting.js index c47fc27a..6ebe224a 100644 --- a/src/tableediting.js +++ b/src/tableediting.js @@ -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; diff --git a/tests/tableediting.js b/tests/tableediting.js index 05175e0e..023d2eed 100644 --- a/tests/tableediting.js +++ b/tests/tableediting.js @@ -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[]' ],