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

Commit 690f32c

Browse files
authored
Merge pull request #1007 from ckeditor/t/1006
Fixed: Live ranges and markers, that are at the end of an element, are now correctly transformed when they are split. Closes #1006.
2 parents 0e29844 + 0b621be commit 690f32c

File tree

4 files changed

+165
-177
lines changed

4 files changed

+165
-177
lines changed

src/model/range.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,13 +472,13 @@ export default class Range {
472472
} else {
473473
const sourceRange = Range.createFromPositionAndShift( sourcePosition, howMany );
474474

475-
// Edge case for merge detla.
475+
// Edge case for merge delta.
476476
if (
477477
deltaType == 'merge' &&
478478
this.isCollapsed &&
479479
( this.start.isEqual( sourceRange.start ) || this.start.isEqual( sourceRange.end ) )
480480
) {
481-
// Collapsed range is in merged element.
481+
// Collapsed range is in merged element, at the beginning or at the end of it.
482482
// Without fix, the range would end up in the graveyard, together with removed element.
483483
// <p>foo</p><p>[]bar</p> -> <p>foobar</p><p>[]</p> -> <p>foobar</p> -> <p>foo[]bar</p>
484484
// <p>foo</p><p>bar[]</p>
@@ -512,7 +512,7 @@ export default class Range {
512512
// <p>c[d</p><w>{<p>a]b</p>}</w><p>xx</p>^ --> <p>c[d</p><w></w><p>xx</p><p>a]b</p> // Note <p>xx</p> inclusion.
513513
// <p>c[d</p>^<w>{<p>a]b</p>}</w> --> <p>c[d</p><p>a]b</p><w></w>
514514
if (
515-
sourceRange.containsPosition( this.end ) &&
515+
( sourceRange.containsPosition( this.end ) || sourceRange.end.isEqual( this.end ) ) &&
516516
this.containsPosition( sourceRange.start ) &&
517517
this.start.isBefore( targetPosition )
518518
) {

tests/manual/markers.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Undo from '@ckeditor/ckeditor5-undo/src/undo';
1717

1818
import buildModelConverter from '../../src/conversion/buildmodelconverter';
1919
import Position from '../../src/model/position';
20-
import LiveRange from '../../src/model/liverange';
20+
import Range from '../../src/model/range';
2121
import ViewAttributeElement from '../../src/view/attributeelement';
2222

2323
const markerNames = [];
@@ -72,7 +72,7 @@ ClassicEditor.create( document.querySelector( '#editor' ), {
7272

7373
model.enqueueChanges( () => {
7474
const root = model.getRoot();
75-
const range = new LiveRange( new Position( root, [ 0, 10 ] ), new Position( root, [ 0, 16 ] ) );
75+
const range = new Range( new Position( root, [ 0, 10 ] ), new Position( root, [ 0, 16 ] ) );
7676
const name = 'highlight:yellow:' + uid();
7777

7878
markerNames.push( name );
@@ -89,7 +89,7 @@ function uid() {
8989

9090
function addHighlight( color ) {
9191
model.enqueueChanges( () => {
92-
const range = LiveRange.createFromRange( model.selection.getFirstRange() );
92+
const range = Range.createFromRange( model.selection.getFirstRange() );
9393
const name = 'highlight:' + color + ':' + uid();
9494

9595
markerNames.push( name );

tests/model/liverange.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ describe( 'LiveRange', () => {
273273
doc.fire( 'change', 'move', changes, null );
274274

275275
expect( live.start.path ).to.deep.equal( [ 0, 1, 4 ] );
276-
expect( live.end.path ).to.deep.equal( [ 0, 2, 0 ] );
276+
expect( live.end.path ).to.deep.equal( [ 2, 2 ] );
277277
expect( spy.calledOnce ).to.be.true;
278278
} );
279279

0 commit comments

Comments
 (0)