Преглед изворни кода

Use selected table cells in isSelectionRectangular().

Maciej Gołaszewski пре 5 година
родитељ
комит
0c09a2e47d

+ 2 - 1
packages/ckeditor5-table/src/commands/mergecellscommand.js

@@ -29,7 +29,8 @@ export default class MergeCellsCommand extends Command {
 	 * @inheritDoc
 	 */
 	refresh() {
-		this.isEnabled = isSelectionRectangular( this.editor.model.document.selection, this.editor.plugins.get( TableUtils ) );
+		const selectedTableCells = getSelectedTableCells( this.editor.model.document.selection );
+		this.isEnabled = isSelectionRectangular( selectedTableCells, this.editor.plugins.get( TableUtils ) );
 	}
 
 	/**

+ 1 - 1
packages/ckeditor5-table/src/tableclipboard.js

@@ -129,7 +129,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( this.editor.model.document.selection, tableUtils ) ) {
+		if ( !isSelectionRectangular( selectedTableCells, tableUtils ) ) {
 			// @if CK_DEBUG // console.log( 'NOT IMPLEMENTED YET: Selection is not rectangular (non-mergeable).' );
 
 			return;

+ 28 - 28
packages/ckeditor5-table/src/utils.js

@@ -179,34 +179,34 @@ export function getColumnIndexes( tableCells ) {
 	return getFirstLastIndexesObject( indexes );
 }
 
-// Checks if the selection contains cells that do not exceed rectangular selection.
-//
-// In a table below:
-//
-//   ┌───┬───┬───┬───┐
-//   │ a │ b │ c │ d │
-//   ├───┴───┼───┤  
-//   │ e     │ f │
-//   ├       ├───┼───┤
-//   │       │ g │ h │
-//   └───────┴───┴───┘
-//
-// Valid selections are these which create a solid rectangle (without gaps), such as:
-//   - a, b (two horizontal cells)
-//   - c, f (two vertical cells)
-//   - a, b, e (cell "e" spans over four cells)
-//   - c, d, f (cell d spans over a cell in the row below)
-//
-// While an invalid selection would be:
-//   - a, c (the unselected cell "b" creates a gap)
-//   - f, g, h (cell "d" spans over a cell from the row of "f" cell - thus creates a gap)
-//
-// @param {module:engine/model/selection~Selection} selection
-// @param {module:table/tableUtils~TableUtils} tableUtils
-// @returns {boolean}
-export function isSelectionRectangular( selection, tableUtils ) {
-	const selectedTableCells = getSelectedTableCells( selection );
-
+/**
+ * Checks if the selection contains cells that do not exceed rectangular selection.
+ *
+ * In a table below:
+ *
+ *   ┌───┬───┬───┬───┐
+ *   │ a │ b │ c │ d
+ *   ├───┴───┼───┤
+ *   │ e     │ f │   │
+ *   ├       ├───┼───┤
+ *   │       │ g │ h │
+ *   └───────┴───┴───┘
+ *
+ * Valid selections are these which create a solid rectangle (without gaps), such as:
+ *   - a, b (two horizontal cells)
+ *   - c, f (two vertical cells)
+ *   - a, b, e (cell "e" spans over four cells)
+ *   - c, d, f (cell d spans over a cell in the row below)
+ *
+ * While an invalid selection would be:
+ *   - a, c (the unselected cell "b" creates a gap)
+ *   - f, g, h (cell "d" spans over a cell from the row of "f" cell - thus creates a gap)
+ *
+ * @param {Array.<module:engine/model/element~Element>} selectedTableCells
+ * @param {module:table/tableUtils~TableUtils} tableUtils
+ * @returns {boolean}
+ */
+export function isSelectionRectangular( selectedTableCells, tableUtils ) {
 	if ( selectedTableCells.length < 2 || !areCellInTheSameTableSection( selectedTableCells ) ) {
 		return false;
 	}