Преглед изворни кода

Updated usages of TableWalker.

Kuba Niegowski пре 5 година
родитељ
комит
152c053b49

+ 3 - 4
packages/ckeditor5-table/src/commands/selectcolumncommand.js

@@ -42,6 +42,7 @@ export default class SelectColumnCommand extends Command {
 		const referenceCells = getSelectionAffectedTableCells( model.document.selection );
 		const firstCell = referenceCells[ 0 ];
 		const lastCell = referenceCells.pop();
+		const table = findAncestor( 'table', firstCell );
 
 		const tableUtils = this.editor.plugins.get( 'TableUtils' );
 		const startLocation = tableUtils.getCellLocation( firstCell );
@@ -52,10 +53,8 @@ export default class SelectColumnCommand extends Command {
 
 		const rangesToSelect = [];
 
-		for ( const cellInfo of new TableWalker( findAncestor( 'table', firstCell ) ) ) {
-			if ( cellInfo.column >= startColumn && cellInfo.column <= endColumn ) {
-				rangesToSelect.push( model.createRangeOn( cellInfo.cell ) );
-			}
+		for ( const cellInfo of new TableWalker( table, { startColumn, endColumn } ) ) {
+			rangesToSelect.push( model.createRangeOn( cellInfo.cell ) );
 		}
 
 		model.change( writer => {

+ 1 - 6
packages/ckeditor5-table/src/converters/downcast.js

@@ -270,12 +270,7 @@ export function downcastTableHeadingColumnsChange( options = {} ) {
 
 		const lastColumnToCheck = ( oldColumns > newColumns ? oldColumns : newColumns ) - 1;
 
-		for ( const tableWalkerValue of new TableWalker( table ) ) {
-			// Skip cells that were not in heading section before and after the change.
-			if ( tableWalkerValue.column > lastColumnToCheck ) {
-				continue;
-			}
-
+		for ( const tableWalkerValue of new TableWalker( table, { endColumn: lastColumnToCheck } ) ) {
 			renameViewTableCellIfRequired( tableWalkerValue, tableAttributes, conversionApi, asWidget );
 		}
 	} );

+ 5 - 13
packages/ckeditor5-table/src/tableclipboard.js

@@ -176,6 +176,8 @@ export default class TableClipboard extends Plugin {
 			const selectedTableMap = [ ...new TableWalker( selectedTable, {
 				startRow: firstRowOfSelection,
 				endRow: lastRowOfSelection,
+				startColumn: firstColumnOfSelection,
+				endColumn: lastColumnOfSelection,
 				includeSpanned: true
 			} ) ];
 
@@ -191,19 +193,9 @@ export default class TableClipboard extends Plugin {
 			// - Inserts cell from a pasted table for a matched slots.
 			//
 			// This ensures proper table geometry after the paste
-			for ( const { row, column, cell, isSpanned } of selectedTableMap ) {
-				if ( column === 0 ) {
-					previousCellInRow = null;
-				}
-
-				// Could use startColumn, endColumn. See: https://github.com/ckeditor/ckeditor5/issues/6785.
-				if ( column < firstColumnOfSelection || column > lastColumnOfSelection ) {
-					// Only update the previousCellInRow for non-spanned slots.
-					if ( !isSpanned ) {
-						previousCellInRow = cell;
-					}
-
-					continue;
+			for ( const { row, column, cell, isSpanned, previousCellInRow: previousCell } of selectedTableMap ) {
+				if ( column == firstColumnOfSelection ) {
+					previousCellInRow = previousCell;
 				}
 
 				// If the slot is occupied by a cell in a selected table - remove it.

+ 9 - 4
packages/ckeditor5-table/src/tableselection.js

@@ -479,10 +479,15 @@ export default class TableSelection extends Plugin {
 		// 2-dimensional array of the selected cells to ease flipping the order of cells for backward selections.
 		const selectionMap = new Array( endRow - startRow + 1 ).fill( null ).map( () => [] );
 
-		for ( const cellInfo of new TableWalker( findAncestor( 'table', anchorCell ), { startRow, endRow } ) ) {
-			if ( cellInfo.column >= startColumn && cellInfo.column <= endColumn ) {
-				selectionMap[ cellInfo.row - startRow ].push( cellInfo.cell );
-			}
+		const walkerOptions = {
+			startRow,
+			endRow,
+			startColumn,
+			endColumn
+		};
+
+		for ( const { row, cell } of new TableWalker( findAncestor( 'table', anchorCell ), walkerOptions ) ) {
+			selectionMap[ row - startRow ].push( cell );
 		}
 
 		const flipVertically = endLocation.row < startLocation.row;

+ 1 - 7
packages/ckeditor5-table/src/tableselection/croptable.js

@@ -58,16 +58,10 @@ export function cropTableToDimensions( sourceTable, cropDimensions, writer, tabl
 		writer.insertElement( 'tableRow', croppedTable, 'end' );
 	}
 
-	const tableMap = [ ...new TableWalker( sourceTable, { startRow, endRow, includeSpanned: true } ) ];
+	const tableMap = [ ...new TableWalker( sourceTable, { startRow, endRow, startColumn, endColumn, includeSpanned: true } ) ];
 
 	// Iterate over source table slots (including empty - spanned - ones).
 	for ( const { row: sourceRow, column: sourceColumn, cell: tableCell, isSpanned } of tableMap ) {
-		// Skip slots outside the cropped area.
-		// Could use startColumn, endColumn. See: https://github.com/ckeditor/ckeditor5/issues/6785.
-		if ( sourceColumn < startColumn || sourceColumn > endColumn ) {
-			continue;
-		}
-
 		// Row index in cropped table.
 		const rowInCroppedTable = sourceRow - startRow;
 		const row = croppedTable.getChild( rowInCroppedTable );