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

Use single crop pass for fixing pasted table layout and cropping pasted table to selection area.

Maciej Gołaszewski 5 лет назад
Родитель
Сommit
081d461870
1 измененных файлов с 9 добавлено и 16 удалено
  1. 9 16
      packages/ckeditor5-table/src/tableclipboard.js

+ 9 - 16
packages/ckeditor5-table/src/tableclipboard.js

@@ -169,24 +169,17 @@ export default class TableClipboard extends Plugin {
 				return;
 			}
 
-			pastedTable = cropTableToDimensions( pastedTable, {
+			// Crop pasted table if:
+			// - Pasted table dimensions exceeds selection area.
+			// - Pasted table has broken layout (ie some cells sticks out by the table dimensions established by the first and last row).
+			const cropDimensions = {
 				startRow: 0,
-				endRow: pasteHeight - 1,
 				startColumn: 0,
-				endColumn: pasteWidth - 1
-			}, writer, tableUtils );
-
-			// Crop pasted table if it extends selection area.
-			if ( selectionHeight < pasteHeight || selectionWidth < pasteWidth ) {
-				const cropDimensions = {
-					startRow: 0,
-					startColumn: 0,
-					endRow: selectionHeight - 1,
-					endColumn: selectionWidth - 1
-				};
-
-				pastedTable = cropTableToDimensions( pastedTable, cropDimensions, writer, tableUtils );
-			}
+				endRow: Math.min( selectionHeight - 1, pasteHeight - 1 ),
+				endColumn: Math.min( selectionWidth - 1, pasteWidth - 1 )
+			};
+
+			pastedTable = cropTableToDimensions( pastedTable, cropDimensions, writer, tableUtils );
 
 			// Holds two-dimensional array that is addressed by [ row ][ column ] that stores cells anchored at given location.
 			const pastedTableLocationMap = createLocationMap( pastedTable, selectionWidth, selectionHeight );