8
0
Просмотр исходного кода

Fix model-selection-range-intersects error in undo after merging two table cells.

Maciej Gołaszewski 5 лет назад
Родитель
Сommit
2001f62ae8

+ 5 - 0
packages/ckeditor5-table/src/commands/mergecellscommand.js

@@ -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 );

+ 29 - 0
packages/ckeditor5-table/tests/tableselection-integration.js

@@ -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;
@@ -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 );