8
0
Quellcode durchsuchen

Fix: Fixed a crash that was happening in some scenarios when undoing table background change.

Szymon Cofalik vor 5 Jahren
Ursprung
Commit
84602ef3b3

+ 1 - 0
packages/ckeditor5-engine/package.json

@@ -39,6 +39,7 @@
     "@ckeditor/ckeditor5-typing": "^17.0.0",
     "@ckeditor/ckeditor5-undo": "^17.0.0",
     "@ckeditor/ckeditor5-widget": "^17.0.0",
+    "@ckeditor/ckeditor5-table": "^17.0.0",
     "eslint": "^5.5.0",
     "eslint-config-ckeditor5": "^2.0.0",
     "husky": "^1.3.1",

+ 8 - 3
packages/ckeditor5-engine/src/model/operation/transform.js

@@ -728,9 +728,14 @@ function padWithNoOps( operations, howMany ) {
 // -----------------------
 
 setTransformation( AttributeOperation, AttributeOperation, ( a, b, context ) => {
-	if ( a.key === b.key ) {
-		// If operations attributes are in conflict, check if their ranges intersect and manage them properly.
-
+	// If operations in conflict, check if their ranges intersect and manage them properly.
+	//
+	// Operations can be in conflict only if:
+	//
+	// * their key is the same (they change the same attribute), and
+	// * they are in the same parent (operations for ranges [ 1 ] - [ 3 ] and [ 2, 0 ] - [ 2, 5 ] change different
+	// elements and can't be in conflict).
+	if ( a.key === b.key && a.range.start.hasSameParentAs( b.range.start ) ) {
 		// First, we want to apply change to the part of a range that has not been changed by the other operation.
 		const operations = a.range.getDifference( b.range ).map( range => {
 			return new AttributeOperation( range, a.key, a.oldValue, a.newValue, 0 );

+ 15 - 0
packages/ckeditor5-engine/tests/model/operation/transform/attribute.js

@@ -172,6 +172,21 @@ describe( 'transform', () => {
 
 				expectClients( '<paragraph><$text attr="bar">Foo Bar</$text></paragraph>' );
 			} );
+
+			// https://github.com/ckeditor/ckeditor5/issues/6265
+			it( 'on elements on different but intersecting "levels"', () => {
+				john.setData( '[<table><tableRow><tableCell><paragraph>Foo</paragraph></tableCell></tableRow></table>]' );
+				kate.setData( '<table><tableRow>[<tableCell><paragraph>Foo</paragraph></tableCell>]</tableRow></table>' );
+
+				john.setAttribute( 'attr', 'foo' );
+				kate.setAttribute( 'attr', 'bar' );
+
+				syncClients();
+
+				expectClients(
+					'<table attr="foo"><tableRow><tableCell attr="bar"><paragraph>Foo</paragraph></tableCell></tableRow></table>'
+				);
+			} );
 		} );
 
 		describe( 'by insert', () => {

+ 2 - 1
packages/ckeditor5-engine/tests/model/operation/transform/utils.js

@@ -12,6 +12,7 @@ import Typing from '@ckeditor/ckeditor5-typing/src/typing';
 import UndoEditing from '@ckeditor/ckeditor5-undo/src/undoediting';
 import BlockQuoteEditing from '@ckeditor/ckeditor5-block-quote/src/blockquoteediting';
 import HeadingEditing from '@ckeditor/ckeditor5-heading/src/headingediting';
+import TableEditing from '@ckeditor/ckeditor5-table/src/tableediting';
 
 import { getData, parse } from '../../../../src/dev-utils/model';
 import { transformSets } from '../../../../src/model/operation/transform';
@@ -37,7 +38,7 @@ export class Client {
 			// UndoEditing is needed for undo command.
 			// Block plugins are needed for proper data serializing.
 			// BoldEditing is needed for bold command.
-			plugins: [ Typing, Paragraph, ListEditing, UndoEditing, BlockQuoteEditing, HeadingEditing, BoldEditing ]
+			plugins: [ Typing, Paragraph, ListEditing, UndoEditing, BlockQuoteEditing, HeadingEditing, BoldEditing, TableEditing ]
 		} ).then( editor => {
 			this.editor = editor;
 			this.document = editor.model.document;