浏览代码

Fix: All content is properly removed after undoing paste in some scenarios.

Szymon Cofalik 6 年之前
父节点
当前提交
8fe2f7d0ee

+ 1 - 3
packages/ckeditor5-engine/src/model/operation/transform.js

@@ -2304,9 +2304,7 @@ function _makeMoveOperationsFromRanges( ranges, targetPosition ) {
 		const op = new MoveOperation(
 			range.start,
 			range.end.offset - range.start.offset,
-			// If the target is the end of the move range this operation doesn't really move anything.
-			// In this case, it is better for OT to use range start instead of range end.
-			targetPosition.isEqual( range.end ) ? range.start : targetPosition,
+			targetPosition,
 			0
 		);
 

+ 39 - 0
packages/ckeditor5-engine/tests/model/operation/transform/undo.js

@@ -5,6 +5,7 @@
 
 import { Client, expectClients, clearBuffer } from './utils.js';
 
+import DocumentFragment from '../../../../src/model/documentfragment';
 import Element from '../../../../src/model/element';
 import Text from '../../../../src/model/text';
 
@@ -612,4 +613,42 @@ describe( 'transform', () => {
 			return new Element( 'heading1', null, new Text( 'Foobar' ) );
 		}
 	} );
+
+	// https://github.com/ckeditor/ckeditor5/issues/1540
+	it( 'paste, select all, paste, undo, undo, redo, redo, redo', () => {
+		const model = john.editor.model;
+
+		john.setData( '<paragraph>[]</paragraph>' );
+
+		model.insertContent( getPastedContent() );
+
+		john.setSelection( [ 0, 0 ], [ 1, 3 ] );
+
+		model.insertContent( getPastedContent() );
+
+		expectClients( '<heading1>Foo</heading1><paragraph>Bar</paragraph>' );
+
+		john.undo();
+
+		expectClients( '<heading1>Foo</heading1><paragraph>Bar</paragraph>' );
+
+		john.undo();
+
+		expectClients( '<paragraph></paragraph>' );
+
+		john.redo();
+
+		expectClients( '<heading1>Foo</heading1><paragraph>Bar</paragraph>' );
+
+		john.redo();
+
+		expectClients( '<heading1>Foo</heading1><paragraph>Bar</paragraph>' );
+
+		function getPastedContent() {
+			return new DocumentFragment( [
+				new Element( 'heading1', null, new Text( 'Foo' ) ),
+				new Element( 'paragraph', null, new Text( 'Bar' ) )
+			] );
+		}
+	} );
 } );