|
@@ -8,7 +8,6 @@
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
import Command from '@ckeditor/ckeditor5-core/src/command';
|
|
import Command from '@ckeditor/ckeditor5-core/src/command';
|
|
|
-import TableWalker from '../tablewalker';
|
|
|
|
|
import { findAncestor, updateNumericAttribute } from './utils';
|
|
import { findAncestor, updateNumericAttribute } from './utils';
|
|
|
import TableUtils from '../tableutils';
|
|
import TableUtils from '../tableutils';
|
|
|
import { getColumnIndexes, getRowIndexes, getSelectedTableCells } from '../utils';
|
|
import { getColumnIndexes, getRowIndexes, getSelectedTableCells } from '../utils';
|
|
@@ -46,6 +45,7 @@ export default class MergeCellsCommand extends Command {
|
|
|
|
|
|
|
|
// All cells will be merged into the first one.
|
|
// All cells will be merged into the first one.
|
|
|
const firstTableCell = selectedTableCells.shift();
|
|
const firstTableCell = selectedTableCells.shift();
|
|
|
|
|
+ const table = findAncestor( 'table', firstTableCell );
|
|
|
|
|
|
|
|
// Set the selection in cell that other cells are being merged to prevent model-selection-range-intersects error in undo.
|
|
// Set the selection in cell that other cells are being merged to prevent model-selection-range-intersects error in undo.
|
|
|
// See https://github.com/ckeditor/ckeditor5/issues/6634.
|
|
// See https://github.com/ckeditor/ckeditor5/issues/6634.
|
|
@@ -57,40 +57,25 @@ export default class MergeCellsCommand extends Command {
|
|
|
updateNumericAttribute( 'colspan', mergeWidth, firstTableCell, writer );
|
|
updateNumericAttribute( 'colspan', mergeWidth, firstTableCell, writer );
|
|
|
updateNumericAttribute( 'rowspan', mergeHeight, firstTableCell, writer );
|
|
updateNumericAttribute( 'rowspan', mergeHeight, firstTableCell, writer );
|
|
|
|
|
|
|
|
|
|
+ const emptyRows = [];
|
|
|
|
|
+
|
|
|
for ( const tableCell of selectedTableCells ) {
|
|
for ( const tableCell of selectedTableCells ) {
|
|
|
const tableRow = tableCell.parent;
|
|
const tableRow = tableCell.parent;
|
|
|
|
|
+
|
|
|
mergeTableCells( tableCell, firstTableCell, writer );
|
|
mergeTableCells( tableCell, firstTableCell, writer );
|
|
|
- removeRowIfEmpty( tableRow, writer );
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if ( !tableRow.childCount ) {
|
|
|
|
|
+ emptyRows.push( table.getChildIndex( tableRow ) );
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ emptyRows.reverse().forEach( row => tableUtils.removeRows( table, { at: row } ) );
|
|
|
|
|
+
|
|
|
writer.setSelection( firstTableCell, 'in' );
|
|
writer.setSelection( firstTableCell, 'in' );
|
|
|
} );
|
|
} );
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// Properly removes an empty row from a table. Updates the `rowspan` attribute of cells that overlap the removed row.
|
|
|
|
|
-//
|
|
|
|
|
-// @param {module:engine/model/element~Element} row
|
|
|
|
|
-// @param {module:engine/model/writer~Writer} writer
|
|
|
|
|
-function removeRowIfEmpty( row, writer ) {
|
|
|
|
|
- if ( row.childCount ) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- const table = row.parent;
|
|
|
|
|
- const removedRowIndex = table.getChildIndex( row );
|
|
|
|
|
-
|
|
|
|
|
- for ( const { cell, row, rowspan } of new TableWalker( table, { endRow: removedRowIndex } ) ) {
|
|
|
|
|
- const overlapsRemovedRow = row + rowspan - 1 >= removedRowIndex;
|
|
|
|
|
-
|
|
|
|
|
- if ( overlapsRemovedRow ) {
|
|
|
|
|
- updateNumericAttribute( 'rowspan', rowspan - 1, cell, writer );
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- writer.remove( row );
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
// Merges two table cells. It will ensure that after merging cells with empty paragraphs the resulting table cell will only have one
|
|
// Merges two table cells. It will ensure that after merging cells with empty paragraphs the resulting table cell will only have one
|
|
|
// paragraph. If one of the merged table cells is empty, the merged table cell will have contents of the non-empty table cell.
|
|
// paragraph. If one of the merged table cells is empty, the merged table cell will have contents of the non-empty table cell.
|
|
|
// If both are empty, the merged table cell will have only one empty paragraph.
|
|
// If both are empty, the merged table cell will have only one empty paragraph.
|