Browse Source

Add internal docs comments.

Maciej Gołaszewski 5 years ago
parent
commit
0ff5a24015
1 changed files with 17 additions and 9 deletions
  1. 17 9
      packages/ckeditor5-table/src/tableclipboard.js

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

@@ -119,9 +119,6 @@ export default class TableClipboard extends Plugin {
 			return;
 			return;
 		}
 		}
 
 
-		// Content table to which we insert a pasted table.
-		const selectedTable = findAncestor( 'table', selectedTableCells[ 0 ] );
-
 		// We might need to crop table before inserting so reference might change.
 		// We might need to crop table before inserting so reference might change.
 		let pastedTable = getTableIfOnlyTableInContent( content );
 		let pastedTable = getTableIfOnlyTableInContent( content );
 
 
@@ -142,7 +139,10 @@ export default class TableClipboard extends Plugin {
 			const pasteHeight = tableUtils.getRows( pastedTable );
 			const pasteHeight = tableUtils.getRows( pastedTable );
 			const pasteWidth = tableUtils.getColumns( pastedTable );
 			const pasteWidth = tableUtils.getColumns( pastedTable );
 
 
-			if ( selectedTableCells.length == 1 ) {
+			// Content table to which we insert a pasted table.
+			const selectedTable = findAncestor( 'table', selectedTableCells[ 0 ] );
+
+			if ( selectedTableCells.length === 1 ) {
 				lastRowOfSelection += pasteHeight - 1;
 				lastRowOfSelection += pasteHeight - 1;
 				lastColumnOfSelection += pasteWidth - 1;
 				lastColumnOfSelection += pasteWidth - 1;
 
 
@@ -172,6 +172,7 @@ export default class TableClipboard extends Plugin {
 			const selectionWidth = lastColumnOfSelectionArea - firstColumnOfSelection + 1;
 			const selectionWidth = lastColumnOfSelectionArea - firstColumnOfSelection + 1;
 
 
 			// The if below is temporal and will be removed when handling this case.
 			// The if below is temporal and will be removed when handling this case.
+			// This if to be removed as handling of replicating cells should be done in replaceSelectedCellsWithPasted().
 			// See: https://github.com/ckeditor/ckeditor5/issues/6769.
 			// See: https://github.com/ckeditor/ckeditor5/issues/6769.
 			if ( selectionHeight > pasteHeight || selectionWidth > pasteWidth ) {
 			if ( selectionHeight > pasteHeight || selectionWidth > pasteWidth ) {
 				// @if CK_DEBUG // console.log( 'NOT IMPLEMENTED YET: Pasted table is smaller than selection area.' );
 				// @if CK_DEBUG // console.log( 'NOT IMPLEMENTED YET: Pasted table is smaller than selection area.' );
@@ -223,8 +224,9 @@ export default class TableClipboard extends Plugin {
 // @param {module:engine/model/writer~Writer} writer
 // @param {module:engine/model/writer~Writer} writer
 function replaceSelectedCellsWithPasted( pastedTable, selectedTable, selectionDimensions, writer ) {
 function replaceSelectedCellsWithPasted( pastedTable, selectedTable, selectionDimensions, writer ) {
 	const {
 	const {
-		firstColumnOfSelection, lastColumnOfSelection, selectionWidth,
-		firstRowOfSelection, lastRowOfSelection, selectionHeight
+		firstColumnOfSelection, lastColumnOfSelection,
+		selectionWidth, selectionHeight,
+		firstRowOfSelection, lastRowOfSelection
 	} = selectionDimensions;
 	} = selectionDimensions;
 
 
 	// Holds two-dimensional array that is addressed by [ row ][ column ] that stores cells anchored at given location.
 	// Holds two-dimensional array that is addressed by [ row ][ column ] that stores cells anchored at given location.
@@ -377,7 +379,7 @@ function createLocationMap( table, width, height ) {
 	return map;
 	return map;
 }
 }
 
 
-// Make selected cell rectangular by splitting the cells that stand out from a rectangular selection.
+// Make selected cells rectangular by splitting the cells that stand out from a rectangular selection.
 //
 //
 // In the table below a selection is shown with "::" and slots with anchor cells are named.
 // In the table below a selection is shown with "::" and slots with anchor cells are named.
 //
 //
@@ -477,12 +479,15 @@ function isAffectedBySelection( rowOrColumn, rowOrColumnSpan, first, last ) {
 	return isInsideSelection || overlapsSelectionFromOutside;
 	return isInsideSelection || overlapsSelectionFromOutside;
 }
 }
 
 
+// Returns adjusted last row index if selection covers part of a row with empty slots (spanned by other cells).
 function adjustLastRowOfSelection( selectedTable, rowIndexes, columnIndexes ) {
 function adjustLastRowOfSelection( selectedTable, rowIndexes, columnIndexes ) {
-	// Corner case...
 	const lastRowMap = Array.from( new TableWalker( selectedTable, {
 	const lastRowMap = Array.from( new TableWalker( selectedTable, {
 		startRow: rowIndexes.last,
 		startRow: rowIndexes.last,
 		endRow: rowIndexes.last
 		endRow: rowIndexes.last
-	} ) ).filter( ( { column } ) => columnIndexes.first <= column && column <= columnIndexes.last );
+	} ) ).filter( ( { column } ) => {
+		// Could use startColumn, endColumn. See: https://github.com/ckeditor/ckeditor5/issues/6785.
+		return columnIndexes.first <= column && column <= columnIndexes.last;
+	} );
 
 
 	const everyCellHasSingleRowspan = lastRowMap.every( ( { rowspan } ) => rowspan === 1 );
 	const everyCellHasSingleRowspan = lastRowMap.every( ( { rowspan } ) => rowspan === 1 );
 
 
@@ -491,9 +496,11 @@ function adjustLastRowOfSelection( selectedTable, rowIndexes, columnIndexes ) {
 		return rowIndexes.last + rowspanAdjustment;
 		return rowIndexes.last + rowspanAdjustment;
 	}
 	}
 
 
+	// Default to the last row index.
 	return rowIndexes.last;
 	return rowIndexes.last;
 }
 }
 
 
+// Returns adjusted last column index if selection covers part of a column with empty slots (spanned by other cells).
 function adjustLastColumnOfSelection( selectedTable, rowIndexes, columnIndexes ) {
 function adjustLastColumnOfSelection( selectedTable, rowIndexes, columnIndexes ) {
 	const lastColumnMap = Array.from( new TableWalker( selectedTable, {
 	const lastColumnMap = Array.from( new TableWalker( selectedTable, {
 		startRow: rowIndexes.first,
 		startRow: rowIndexes.first,
@@ -508,5 +515,6 @@ function adjustLastColumnOfSelection( selectedTable, rowIndexes, columnIndexes )
 		return columnIndexes.last + colspanAdjustment;
 		return columnIndexes.last + colspanAdjustment;
 	}
 	}
 
 
+	// Default to the last column index.
 	return columnIndexes.last;
 	return columnIndexes.last;
 }
 }