Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #309 from ckeditor/i/6634
Browse files Browse the repository at this point in the history
Internal: Merge table cells now set selection in the merged cell before merging other cells into it. Closes ckeditor/ckeditor5#6634. See ckeditor/ckeditor5#6639.
  • Loading branch information
Reinmar authored Apr 22, 2020
2 parents 856889e + 1b35da4 commit 15016bf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/commands/mergecellscommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export default class MergeCellsCommand extends Command {
// All cells will be merge into the first one.
const firstTableCell = selectedTableCells.shift();

// 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.
// May be fixed by: https://github.com/ckeditor/ckeditor5/issues/6639.
writer.setSelection( firstTableCell, 0 );

// Update target cell dimensions.
const { mergeWidth, mergeHeight } = getMergeDimensions( firstTableCell, selectedTableCells, tableUtils );
updateNumericAttribute( 'colspan', mergeWidth, firstTableCell, writer );
Expand Down
29 changes: 29 additions & 0 deletions tests/tableselection-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import DomEventData from '@ckeditor/ckeditor5-engine/src/view/observer/domeventd
import { getCode } from '@ckeditor/ckeditor5-utils/src/keyboard';
import Input from '@ckeditor/ckeditor5-typing/src/input';
import ViewText from '@ckeditor/ckeditor5-engine/src/view/text';
import UndoEditing from '@ckeditor/ckeditor5-undo/src/undoediting';

describe( 'TableSelection - integration', () => {
let editor, model, tableSelection, modelRoot, element, viewDocument;
Expand Down Expand Up @@ -221,6 +222,34 @@ describe( 'TableSelection - integration', () => {
} );
} );

describe( 'with undo', () => {
beforeEach( async () => {
await setupEditor( [ UndoEditing ] );
} );

// See https://github.com/ckeditor/ckeditor5/issues/6634.
it( 'works with merge cells command', () => {
setModelData( editor.model, modelTable( [ [ '00', '01' ] ] ) );

tableSelection._setCellSelection(
modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
modelRoot.getNodeByPath( [ 0, 0, 1 ] )
);

editor.execute( 'mergeTableCells' );

assertEqualMarkup( getModelData( model ), modelTable( [
[ { colspan: 2, contents: '<paragraph>[00</paragraph><paragraph>01]</paragraph>' } ]
] ) );

editor.execute( 'undo' );

assertEqualMarkup( getModelData( model ), modelTable( [
[ '[]00', '01' ]
] ) );
} );
} );

async function setupEditor( plugins ) {
element = document.createElement( 'div' );
document.body.appendChild( element );
Expand Down

0 comments on commit 15016bf

Please sign in to comment.