8
0
Просмотр исходного кода

Fixed move operation for unwrap.

Piotrek Koszuliński 9 лет назад
Родитель
Сommit
25448d526a

+ 14 - 2
packages/ckeditor5-engine/src/model/range.js

@@ -455,15 +455,27 @@ export default class Range {
 			if ( deltaType == 'split' && this.containsPosition( sourcePosition ) ) {
 				ranges[ 0 ].end = ranges[ 1 ].end;
 				ranges.pop();
-			} else if ( type == 'move' && deltaType == 'wrap' ) {
+			}
+			// Don't ask. Just debug.
+			// Like this: https://github.com/ckeditor/ckeditor5-engine/issues/841#issuecomment-282706488.
+			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>
+				// <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 ) ];
 				}
+			} else if ( type == 'move' && deltaType == 'unwrap' ) {
+				// <w><p>a[b</p></w><p>c]d</p> -> <p>a[b</p><w></w><p>c]d</p>
+				if ( this.containsPosition( sourcePosition.getShiftedBy( howMany ) ) ) {
+					return [ new Range( ranges[ 1 ].start, ranges[ 0 ].end ) ];
+				}
+				// <p>a[b</p><w><p>c]d</p></w> -> <p>a[b</p><p>c]d</p><w></w>
+				else if ( this.containsPosition( sourcePosition ) ) {
+					return [ new Range( ranges[ 0 ].start, ranges[ 2 ].end ) ];
+				}
 			}
 
 			return ranges;

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

@@ -490,7 +490,7 @@ describe( 'LiveRange', () => {
 
 				doc.batch().unwrap( root.getChild( 0 ) );
 
-				expect( stringify( root, live ) ).to.equal( '<p>a[b</p><p>x</p><<p>c]d</p>' );
+				expect( stringify( root, live ) ).to.equal( '<p>a[b</p><p>x</p><p>c]d</p>' );
 			} );
 
 			it( 'its end is intersecting with the wrapper to remove', () => {