8
0
Pārlūkot izejas kodu

Merge pull request #186 from ckeditor/t/185

Fix: Table rows will not be added on tab key press if the associated command is disabled. Closes #185.
Maciej 6 gadi atpakaļ
vecāks
revīzija
5c149a068f

+ 7 - 1
packages/ckeditor5-table/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;

+ 16 - 0
packages/ckeditor5-table/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[]' ],