8
0
Просмотр исходного кода

Internal: Introduced support for removing multiple rows using RemoveRowCommand.

Marek Lewandowski 5 лет назад
Родитель
Сommit
1f7e6b82c2
1 измененных файлов с 22 добавлено и 11 удалено
  1. 22 11
      packages/ckeditor5-table/src/commands/removerowcommand.js

+ 22 - 11
packages/ckeditor5-table/src/commands/removerowcommand.js

@@ -37,28 +37,39 @@ export default class RemoveRowCommand extends Command {
 	 * @inheritDoc
 	 */
 	execute() {
-		const tableCell = this._getReferenceCells().next().value;
-		const tableRow = tableCell.parent;
-		const table = tableRow.parent;
+		const referenceCells = Array.from( this._getReferenceCells() );
+		const removedRowIndexes = {
+			first: referenceCells[ 0 ].parent.index,
+			last: referenceCells[ referenceCells.length - 1 ].parent.index
+		};
+		const firstCell = referenceCells[ 0 ];
+		const table = firstCell.parent.parent;
 
-		const removedRowIndex = table.getChildIndex( tableRow );
+		const tableMap = [ ...new TableWalker( table, { endRow: removedRowIndexes.last } ) ];
 
-		const tableMap = [ ...new TableWalker( table, { endRow: removedRowIndex } ) ];
-
-		const cellData = tableMap.find( value => value.cell === tableCell );
+		const firstCellData = tableMap.find( value => value.cell === firstCell );
 
 		const headingRows = table.getAttribute( 'headingRows' ) || 0;
 
-		const columnToFocus = cellData.column;
+		const columnToFocus = firstCellData.column;
 
 		this.editor.model.change( writer => {
 			// Temporary workaround to avoid the "model-selection-range-intersects" error.
 			writer.setSelection( writer.createSelection( table, 'on' ) );
 
-			this._removeRow( headingRows, removedRowIndex, table, writer, tableMap, tableRow );
+			let cellToFocus;
+
+			for ( let i = removedRowIndexes.last; i >= removedRowIndexes.first; i-- ) {
+				const removedRowIndex = i;
+				const tableRow = table.getChild( removedRowIndex );
+				this._removeRow( headingRows, removedRowIndex, table, writer, tableMap, tableRow );
 
-			const cellToFocus = getCellToFocus( table, removedRowIndex, columnToFocus );
-			writer.setSelection( writer.createPositionAt( cellToFocus, 0 ) );
+				cellToFocus = getCellToFocus( table, removedRowIndex, columnToFocus );
+			}
+
+			if ( cellToFocus ) {
+				writer.setSelection( writer.createPositionAt( cellToFocus, 0 ) );
+			}
 		} );
 	}