浏览代码

Cut table cells to a selection bounding box before paste.

Maciej Gołaszewski 5 年之前
父节点
当前提交
5ad37bfc64

+ 6 - 10
packages/ckeditor5-table/src/tableclipboard.js

@@ -133,11 +133,7 @@ export default class TableClipboard extends Plugin {
 			// Currently not handled. The selected table content should be trimmed to a rectangular selection.
 			// See: https://github.com/ckeditor/ckeditor5/issues/6122.
 			if ( !isSelectionRectangular( selectedTableCells, tableUtils ) ) {
-				// @if CK_DEBUG // console.log( 'NOT IMPLEMENTED YET: Selection is not rectangular (non-mergeable).' );
-
 				prepareLandingPlace( selectedTableCells, writer );
-
-				// return;
 			}
 
 			const { last: lastColumnOfSelection, first: firstColumnOfSelection } = getColumnIndexes( selectedTableCells );
@@ -308,15 +304,15 @@ function prepareLandingPlace( selectedTableCells, writer ) {
 	const { first: firstRow, last: lastRow } = getRowIndexes( selectedTableCells );
 	const { first: firstColumn, last: lastColumn } = getColumnIndexes( selectedTableCells );
 
-	if ( firstRow > 0 ) {
-		cutCellsHorizontallyAt( table, firstRow, 0, writer, { firstRow: 0, firstColumn, lastRow: 1000, lastColumn } );
-	}
-
-	cutCellsHorizontallyAt( table, lastRow + 1, firstRow, writer, { firstRow: 0, firstColumn, lastRow: 1000, lastColumn } );
-
 	if ( firstColumn > 0 ) {
 		cutCellsVerticallyAt( table, firstColumn, 0, writer, { firstRow, firstColumn: 0, lastRow, lastColumn: 1000 } );
 	}
 
 	cutCellsVerticallyAt( table, lastColumn + 1, firstColumn, writer, { firstRow, firstColumn: 0, lastRow, lastColumn: 1000 } );
+
+	if ( firstRow > 0 ) {
+		cutCellsHorizontallyAt( table, firstRow, 0, writer, { firstRow: 0, firstColumn, lastRow: 1000, lastColumn } );
+	}
+
+	cutCellsHorizontallyAt( table, lastRow + 1, firstRow, writer, { firstRow: 0, firstColumn, lastRow: 1000, lastColumn } );
 }

+ 3 - 2
packages/ckeditor5-table/src/utils.js

@@ -285,8 +285,9 @@ export function cutCellsVerticallyAt( table, headingColumnsToSet, currentHeading
 function filterToBoundingBox( boundingBox ) {
 	const { firstRow, firstColumn, lastRow, lastColumn } = boundingBox;
 
-	return ( { row, column } ) => {
-		return ( ( firstRow <= row ) && ( row <= lastRow ) ) && ( firstColumn <= column && column <= lastColumn );
+	return ( { row, column, colspan, rowspan } ) => {
+		return ( ( firstRow <= row + rowspan - 1 ) && ( row + rowspan - 1 <= lastRow ) ) &&
+			( firstColumn <= column + colspan - 1 && column + colspan - 1 <= lastColumn );
 	};
 }
 

+ 6 - 6
packages/ckeditor5-table/tests/tableclipboard-paste.js

@@ -1422,29 +1422,29 @@ describe( 'table clipboard', () => {
 					// | 00      |    | 03 | 04           |
 					// +         +    +    +----+----+----+
 					// |         |    |    | 14 | 15 | 16 |
-					// +----+----+----+----+----+----+----+
+					// +         +----+----+----+----+----+
 					// |         | aa | ab | ac |         |
 					// +----+----+----+----+----+----+----+
 					// | 30 | 31 | ba | bb | bc | 35 | 36 |
 					// +    +----+----+----+----+----+----+
 					// |    | 41 | ca | cb | cc | 45      |
 					// +    +----+----+----+----+         +
-					// |    | 51 | 52 | 53 | 54 |         |
+					// |    | 51 | 52 |    | 54 |         |
 					// +----+----+----+    +----+         +
 					// | 60 | 61 | 62 |    | 64 |         |
 					// +----+----+----+----+----+----+----+
 					assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
 						[
-							{ contents: '00', colspan: 2, rowspan: 2 },
+							{ contents: '00', colspan: 2, rowspan: 3 },
 							{ contents: '', rowspan: 2 },
 							{ contents: '03', rowspan: 2 },
-							'04', '05', '06'
+							{ contents: '04', colspan: 3 }
 						],
 						[ '14', '15', '16' ],
-						[ { contents: '', colspan: 2 }, 'aa', 'ab', 'ac', { contents: '', colspan: 2 } ],
+						[ 'aa', 'ab', 'ac', { contents: '', colspan: 2 } ],
 						[ { contents: '30', rowspan: 3 }, '31', 'ba', 'bb', 'bc', '35', '36' ],
 						[ '41', 'ca', 'cb', 'cc', { contents: '45', colspan: 2, rowspan: 3 } ],
-						[ '51', '52', { contents: '53', rowspan: 2 }, '54' ],
+						[ '51', '52', { contents: '', rowspan: 2 }, '54' ],
 						[ '60', '61', '62', '64' ]
 					] ) );
 				} );