diff --git a/src/controller/datacontroller.js b/src/controller/datacontroller.js index a20a003b7..1ec51a13f 100644 --- a/src/controller/datacontroller.js +++ b/src/controller/datacontroller.js @@ -297,6 +297,7 @@ export default class DataController { */ set( data ) { let newData = {}; + if ( typeof data === 'string' ) { newData.main = data; // Default root is 'main'. To set data on a different root, object should be passed. } else { diff --git a/src/model/writer.js b/src/model/writer.js index eac63883a..c356b2f0e 100644 --- a/src/model/writer.js +++ b/src/model/writer.js @@ -1349,10 +1349,31 @@ export default class Writer { const elementBefore = positionOrRange.nodeBefore; const elementAfter = positionOrRange.nodeAfter; - const affectedOnLeft = markerRange.start.parent == elementBefore && markerRange.start.isAtEnd; - const affectedOnRight = markerRange.end.parent == elementAfter && markerRange.end.offset == 0; - - isAffected = affectedOnLeft || affectedOnRight; + // Start:
Foo[
Bar]
+ // After merge:Foo[Bar]
+ // After undoing split:Foo
[Bar]
<-- incorrect, needs remembering for undo. + // + const affectedInLeftElement = markerRange.start.parent == elementBefore && markerRange.start.isAtEnd; + + // Start:[Foo
]Bar
+ // After merge:[Foo]Bar
+ // After undoing split:[Foo]
Bar
<-- incorrect, needs remembering for undo. + // + const affectedInRightElement = markerRange.end.parent == elementAfter && markerRange.end.offset == 0; + + // Start:[Foo
]Bar
+ // After merge:[Foo]Bar
+ // After undoing split:[Foo]
Bar
<-- incorrect, needs remembering for undo. + // + const affectedAfterLeftElement = markerRange.end.nodeAfter == elementAfter; + + // Start:Foo
[Bar]
+ // After merge:Foo[Bar]
+ // After undoing split:Foo
[Bar]
<-- incorrect, needs remembering for undo. + // + const affectedBeforeRightElement = markerRange.start.nodeAfter == elementAfter; + + isAffected = affectedInLeftElement || affectedInRightElement || affectedAfterLeftElement || affectedBeforeRightElement; } if ( isAffected ) { diff --git a/tests/model/writer.js b/tests/model/writer.js index a7afca994..8724ca37d 100644 --- a/tests/model/writer.js +++ b/tests/model/writer.js @@ -1425,29 +1425,50 @@ describe( 'Writer', () => { expect( docFrag.getChild( 0 ).getChild( 0 ).data ).to.equal( 'foobar' ); } ); - it( 'should create a marker operation if a marker was affected', () => { - const markerRange = new Range( Position._createAt( p2, 0 ), Position._createAt( p2, 0 ) ); + describe( 'should create a marker operation if a marker was affected', () => { + it( 'Foo[
Bar]
', () => { + test( p1, 'end', p2, 0 ); + } ); - addMarker( 'name', { - range: markerRange, - usingOperation: true + it( '[Foo
]Bar
', () => { + test( p1, 0, p2, 0 ); } ); - const documentVersion = model.document.version; + it( '[Foo
]Bar
', () => { + test( p1, 0, root, 1 ); + } ); - merge( Position._createAfter( p1 ) ); + it( 'Foo
[Bar]
', () => { + test( root, 1, p2, 'end' ); + } ); - const history = model.document.history; + function test( startElement, startOffset, endElement, endOffset ) { + const markerRange = new Range( + Position._createAt( startElement, startOffset ), + Position._createAt( endElement, endOffset ) + ); - const lastOperation = history._operations[ history._operations.length - 1 ]; - const secondLastOperation = history._operations[ history._operations.length - 2 ]; + addMarker( 'name', { + range: markerRange, + usingOperation: true + } ); - expect( secondLastOperation.type ).to.equal( 'marker' ); - expect( secondLastOperation.oldRange.isEqual( markerRange ) ); - expect( secondLastOperation.newRange.isEqual( markerRange ) ); + const documentVersion = model.document.version; - expect( lastOperation.type ).to.equal( 'merge' ); - expect( model.document.version ).to.equal( documentVersion + 2 ); + merge( Position._createAfter( p1 ) ); + + const history = model.document.history; + + const lastOperation = history._operations[ history._operations.length - 1 ]; + const secondLastOperation = history._operations[ history._operations.length - 2 ]; + + expect( secondLastOperation.type ).to.equal( 'marker' ); + expect( secondLastOperation.oldRange.isEqual( markerRange ) ); + expect( secondLastOperation.newRange.isEqual( markerRange ) ); + + expect( lastOperation.type ).to.equal( 'merge' ); + expect( model.document.version ).to.equal( documentVersion + 2 ); + } } ); it( 'should not create a marker operation if affected marker was not using operations', () => {