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

Commit

Permalink
Merge pull request #1007 from ckeditor/t/1006
Browse files Browse the repository at this point in the history
Fixed: Live ranges and markers, that are at the end of an element, are now correctly transformed when they are split. Closes #1006.
  • Loading branch information
Reinmar authored Jul 12, 2017
2 parents 0e29844 + 0b621be commit 690f32c
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 177 deletions.
6 changes: 3 additions & 3 deletions src/model/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,13 +472,13 @@ export default class Range {
} else {
const sourceRange = Range.createFromPositionAndShift( sourcePosition, howMany );

// Edge case for merge detla.
// Edge case for merge delta.
if (
deltaType == 'merge' &&
this.isCollapsed &&
( this.start.isEqual( sourceRange.start ) || this.start.isEqual( sourceRange.end ) )
) {
// Collapsed range is in merged element.
// Collapsed range is in merged element, at the beginning or at the end of it.
// Without fix, the range would end up in the graveyard, together with removed element.
// <p>foo</p><p>[]bar</p> -> <p>foobar</p><p>[]</p> -> <p>foobar</p> -> <p>foo[]bar</p>
// <p>foo</p><p>bar[]</p>
Expand Down Expand Up @@ -512,7 +512,7 @@ export default class Range {
// <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.
// <p>c[d</p>^<w>{<p>a]b</p>}</w> --> <p>c[d</p><p>a]b</p><w></w>
if (
sourceRange.containsPosition( this.end ) &&
( sourceRange.containsPosition( this.end ) || sourceRange.end.isEqual( this.end ) ) &&
this.containsPosition( sourceRange.start ) &&
this.start.isBefore( targetPosition )
) {
Expand Down
6 changes: 3 additions & 3 deletions tests/manual/markers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Undo from '@ckeditor/ckeditor5-undo/src/undo';

import buildModelConverter from '../../src/conversion/buildmodelconverter';
import Position from '../../src/model/position';
import LiveRange from '../../src/model/liverange';
import Range from '../../src/model/range';
import ViewAttributeElement from '../../src/view/attributeelement';

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

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

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

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

markerNames.push( name );
Expand Down
2 changes: 1 addition & 1 deletion tests/model/liverange.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ describe( 'LiveRange', () => {
doc.fire( 'change', 'move', changes, null );

expect( live.start.path ).to.deep.equal( [ 0, 1, 4 ] );
expect( live.end.path ).to.deep.equal( [ 0, 2, 0 ] );
expect( live.end.path ).to.deep.equal( [ 2, 2 ] );
expect( spy.calledOnce ).to.be.true;
} );

Expand Down
Loading

0 comments on commit 690f32c

Please sign in to comment.