8
0
Prechádzať zdrojové kódy

Refactor cell replace algorithm to make more clear.

Maciej Gołaszewski 5 rokov pred
rodič
commit
70b23ae7bc

+ 11 - 14
packages/ckeditor5-table/src/tableclipboard.js

@@ -178,7 +178,7 @@ export default class TableClipboard extends Plugin {
 				includeSpanned: true
 			} ) ];
 
-			for ( const { column, row, cell, isSpanned } of tableMap ) {
+			for ( const { row, column, cell, isSpanned } of tableMap ) {
 				if ( column === 0 ) {
 					previousCellInRow = null;
 				}
@@ -190,25 +190,22 @@ export default class TableClipboard extends Plugin {
 					continue;
 				}
 
-				// Map current table location to inserted table location.
+				// If the slot is occupied by a cell in a selected table - remove it.
+				// The slot of this cell will be either:
+				// - Replaced by a pasted table cell.
+				// - Spanned by a previously pasted table cell.
+				if ( !isSpanned ) {
+					writer.remove( cell );
+				}
+
+				// Map current table slot location to an inserted table slot location.
 				const pastedCell = pastedTableMap[ row - firstRowOfSelection ][ column - firstColumnOfSelection ];
 
-				// There is no cell to insert (might be spanned by other cell in a pasted table) so...
+				// There is no cell to insert (might be spanned by other cell in a pasted table) - advance to the next content table slot.
 				if ( !pastedCell ) {
-					// ...if the cell is anchored in current location (not-spanned slot) then remove that cell from content table...
-					if ( !isSpanned ) {
-						writer.remove( cell );
-					}
-
-					// ...and advance to next content table slot.
 					continue;
 				}
 
-				// Remove cells from anchor slots (not spanned by other cells).
-				if ( !isSpanned ) {
-					writer.remove( cell );
-				}
-
 				// Clone cell to insert (to duplicate its attributes and children).
 				// Cloning is required to support repeating pasted table content when inserting to a bigger selection.
 				const cellToInsert = pastedCell._clone( true );

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

@@ -55,6 +55,7 @@ export function cropTableToDimensions( sourceTable, startRow, startColumn, endRo
 	// 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;
 		}