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

Fixed a crash that was happening in some scenarios when undoing table background change #1832

Merged
merged 2 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@ckeditor/ckeditor5-link": "^18.0.0",
"@ckeditor/ckeditor5-list": "^18.0.0",
"@ckeditor/ckeditor5-paragraph": "^18.0.0",
"@ckeditor/ckeditor5-table": "^18.0.0",
"@ckeditor/ckeditor5-theme-lark": "^18.0.0",
"@ckeditor/ckeditor5-typing": "^18.0.0",
"@ckeditor/ckeditor5-undo": "^18.0.0",
Expand Down
11 changes: 8 additions & 3 deletions src/model/operation/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
15 changes: 15 additions & 0 deletions tests/model/operation/transform/attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
3 changes: 2 additions & 1 deletion tests/model/operation/transform/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down