8
0
Pārlūkot izejas kodu

Internal: Fixed a case when removing last row would crash the editor.

Marek Lewandowski 5 gadi atpakaļ
vecāks
revīzija
018c7a6bbf

+ 6 - 2
packages/ckeditor5-table/src/commands/removerowcommand.js

@@ -104,8 +104,12 @@ export default class RemoveRowCommand extends Command {
 }
 
 // Returns a cell that should be focused before removing the row, belonging to the same column as the currently focused cell.
-function getCellToFocus( table, removedRow, columnToFocus ) {
-	const row = table.getChild( removedRow );
+function getCellToFocus( table, removedRowIndex, columnToFocus ) {
+	let row = table.getChild( removedRowIndex );
+
+	if ( !row ) {
+		row = table.getChild( table.childCount - 1 );
+	}
 
 	// Default to first table cell.
 	let cellToFocus = row.getChild( 0 );

+ 13 - 0
packages/ckeditor5-table/tests/commands/removerowcommand.js

@@ -85,6 +85,19 @@ describe( 'RemoveRowCommand', () => {
 			] ) );
 		} );
 
+		it( 'should remove last row', () => {
+			setData( model, modelTable( [
+				[ '00', '01' ],
+				[ '[]10', '11' ]
+			] ) );
+
+			command.execute();
+
+			assertEqualMarkup( getData( model ), modelTable( [
+				[ '[]00', '01' ]
+			] ) );
+		} );
+
 		it( 'should change heading rows if removing a heading row', () => {
 			setData( model, modelTable( [
 				[ '00', '01' ],