Răsfoiți Sursa

Change the cut cells horizontally utility to single function.

Maciej Gołaszewski 5 ani în urmă
părinte
comite
01002e86a7

+ 11 - 7
packages/ckeditor5-table/src/commands/setheaderrowcommand.js

@@ -77,11 +77,7 @@ export default class SetHeaderRowCommand extends Command {
 			if ( headingRowsToSet ) {
 				// Changing heading rows requires to check if any of a heading cell is overlapping vertically the table head.
 				// Any table cell that has a rowspan attribute > 1 will not exceed the table head so we need to fix it in rows below.
-				const cellsToSplit = getOverlappingCells( table, headingRowsToSet, currentHeadingRows );
-
-				for ( const cell of cellsToSplit ) {
-					splitHorizontally( cell, headingRowsToSet, writer );
-				}
+				cutCellsHorizontallyAt( table, headingRowsToSet, currentHeadingRows, writer );
 			}
 
 			updateNumericAttribute( 'headingRows', headingRowsToSet, table, writer, 0 );
@@ -103,13 +99,21 @@ export default class SetHeaderRowCommand extends Command {
 	}
 }
 
+export function cutCellsHorizontallyAt( table, headingRowsToSet, currentHeadingRows, writer ) {
+	const cellsToSplit = getOverlappingCells( table, headingRowsToSet, currentHeadingRows );
+
+	for ( const cell of cellsToSplit ) {
+		splitHorizontally( cell, headingRowsToSet, writer );
+	}
+}
+
 // Returns cells that span beyond the new heading section.
 //
 // @param {module:engine/model/element~Element} table The table to check.
 // @param {Number} headingRowsToSet New heading rows attribute.
 // @param {Number} currentHeadingRows Current heading rows attribute.
 // @returns {Array.<module:engine/model/element~Element>}
-export function getOverlappingCells( table, headingRowsToSet, currentHeadingRows ) {
+function getOverlappingCells( table, headingRowsToSet, currentHeadingRows ) {
 	const cellsToSplit = [];
 
 	const startAnalysisRow = headingRowsToSet > currentHeadingRows ? currentHeadingRows : 0;
@@ -132,7 +136,7 @@ export function getOverlappingCells( table, headingRowsToSet, currentHeadingRows
 // @param {module:engine/model/element~Element} tableCell
 // @param {Number} headingRows
 // @param {module:engine/model/writer~Writer} writer
-export function splitHorizontally( tableCell, headingRows, writer ) {
+function splitHorizontally( tableCell, headingRows, writer ) {
 	const tableRow = tableCell.parent;
 	const table = tableRow.parent;
 	const rowIndex = tableRow.index;

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

@@ -14,7 +14,7 @@ import TableWalker from './tablewalker';
 import { getColumnIndexes, getRowIndexes, isSelectionRectangular } from './utils';
 import { findAncestor } from './commands/utils';
 import { cropTableToDimensions } from './tableselection/croptable';
-import { getOverlappingCells, splitHorizontally } from './commands/setheaderrowcommand';
+import { cutCellsHorizontallyAt } from './commands/setheaderrowcommand';
 import TableUtils from './tableutils';
 
 /**
@@ -309,16 +309,8 @@ function prepareLandingPlace( selectedTableCells, writer ) {
 	const { first: firstRow, last: lastRow } = getRowIndexes( selectedTableCells );
 
 	if ( firstRow > 0 ) {
-		const cellsToSplitHorizontallyAtFirstRow = getOverlappingCells( table, firstRow, 0 );
-
-		for ( const cell of cellsToSplitHorizontallyAtFirstRow ) {
-			splitHorizontally( cell, firstRow, writer );
-		}
+		cutCellsHorizontallyAt( table, firstRow, 0, writer );
 	}
 
-	const cellsToSplitHorizontallyAtLastRow = getOverlappingCells( table, lastRow + 1, firstRow );
-
-	for ( const cell of cellsToSplitHorizontallyAtLastRow ) {
-		splitHorizontally( cell, lastRow + 1, writer );
-	}
+	cutCellsHorizontallyAt( table, lastRow + 1, firstRow, writer );
 }