8
0
Pārlūkot izejas kodu

Fixed move operation for wrap.

Piotrek Koszuliński 8 gadi atpakaļ
vecāks
revīzija
300339deb1

+ 9 - 0
packages/ckeditor5-engine/src/model/range.js

@@ -455,6 +455,15 @@ export default class Range {
 			if ( deltaType == 'split' && this.containsPosition( sourcePosition ) ) {
 				ranges[ 0 ].end = ranges[ 1 ].end;
 				ranges.pop();
+			} else if ( type == 'move' && deltaType == 'wrap' ) {
+				// <p>a[b</p><w></w><p>c]d</p> -> <w><p>a[b</p></w><p>c]d</p>
+				if ( this.containsPosition( targetPosition ) ) {
+					return [ new Range( ranges[ 2 ].start, ranges[ 1 ].end ) ];
+				}
+				// <p>a[b</p><p>c]d</p><w></w> -><p>a[b</p><w><p>c]d</p></w>
+				else if ( this.containsPosition( sourcePosition ) ) {
+					return [ new Range( ranges[ 0 ].start, ranges[ 1 ].end ) ];
+				}
 			}
 
 			return ranges;

+ 2 - 2
packages/ckeditor5-engine/tests/model/liverange.js

@@ -421,7 +421,7 @@ describe( 'LiveRange', () => {
 				// [<p>ab</p><p>x</p>]
 				doc.batch().wrap( new Range( new Position( root, [ 0 ] ), new Position( root, [ 2 ] ) ), 'w' );
 
-				expect( stringify( root, live ) ).to.equal( '<w><p>a[b</p>p>x</p></w><<p>c]d</p>' );
+				expect( stringify( root, live ) ).to.equal( '<w><p>a[b</p><p>x</p></w><p>c]d</p>' );
 			} );
 
 			it( 'its end is intersecting with the wrapped range (multiple elements)', () => {
@@ -430,7 +430,7 @@ describe( 'LiveRange', () => {
 				live = new LiveRange( doc.selection.getFirstPosition(), doc.selection.getLastPosition() );
 
 				// [<p>x</p><p>cd</p>]
-				doc.batch().wrap( new Range( new Position( root, [ 2 ] ), new Position( root, [ 3 ] ) ), 'w' );
+				doc.batch().wrap( new Range( new Position( root, [ 1 ] ), new Position( root, [ 3 ] ) ), 'w' );
 
 				expect( stringify( root, live ) ).to.equal( '<p>a[b</p><w><p>x</p><p>c]d</p></w>' );
 			} );