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

Commit 08855d3

Browse files
authored
Merge pull request #1683 from ckeditor/t/ckeditor5/1540
Fix: All content is properly removed after undoing paste in some scenarios. Closes [ckeditor/ckeditor5#1540](ckeditor/ckeditor5#1540).
2 parents 3b53d5a + 587a15d commit 08855d3

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

src/model/operation/transform.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,9 +2304,7 @@ function _makeMoveOperationsFromRanges( ranges, targetPosition ) {
23042304
const op = new MoveOperation(
23052305
range.start,
23062306
range.end.offset - range.start.offset,
2307-
// If the target is the end of the move range this operation doesn't really move anything.
2308-
// In this case, it is better for OT to use range start instead of range end.
2309-
targetPosition.isEqual( range.end ) ? range.start : targetPosition,
2307+
targetPosition,
23102308
0
23112309
);
23122310

tests/model/operation/transform/insert.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,7 @@ describe( 'transform', () => {
291291
);
292292
} );
293293

294-
// Incorrect result due to wrap/unwrap being represented by inserts and moves.
295-
it.skip( 'element in same path #2', () => {
294+
it( 'element in same path #2', () => {
296295
john.setData( '<paragraph>Foo[]</paragraph>' );
297296
kate.setData( '[<paragraph>Foo</paragraph>]' );
298297

tests/model/operation/transform/undo.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { Client, expectClients, clearBuffer } from './utils.js';
77

8+
import DocumentFragment from '../../../../src/model/documentfragment';
89
import Element from '../../../../src/model/element';
910
import Text from '../../../../src/model/text';
1011

@@ -612,4 +613,42 @@ describe( 'transform', () => {
612613
return new Element( 'heading1', null, new Text( 'Foobar' ) );
613614
}
614615
} );
616+
617+
// https://github.com/ckeditor/ckeditor5/issues/1540
618+
it( 'paste, select all, paste, undo, undo, redo, redo, redo', () => {
619+
const model = john.editor.model;
620+
621+
john.setData( '<paragraph>[]</paragraph>' );
622+
623+
model.insertContent( getPastedContent() );
624+
625+
john.setSelection( [ 0, 0 ], [ 1, 3 ] );
626+
627+
model.insertContent( getPastedContent() );
628+
629+
expectClients( '<heading1>Foo</heading1><paragraph>Bar</paragraph>' );
630+
631+
john.undo();
632+
633+
expectClients( '<heading1>Foo</heading1><paragraph>Bar</paragraph>' );
634+
635+
john.undo();
636+
637+
expectClients( '<paragraph></paragraph>' );
638+
639+
john.redo();
640+
641+
expectClients( '<heading1>Foo</heading1><paragraph>Bar</paragraph>' );
642+
643+
john.redo();
644+
645+
expectClients( '<heading1>Foo</heading1><paragraph>Bar</paragraph>' );
646+
647+
function getPastedContent() {
648+
return new DocumentFragment( [
649+
new Element( 'heading1', null, new Text( 'Foo' ) ),
650+
new Element( 'paragraph', null, new Text( 'Bar' ) )
651+
] );
652+
}
653+
} );
615654
} );

tests/model/operation/transform/wrap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ describe( 'transform', () => {
382382
expectClients( '<blockQuote><paragraph>c</paragraph></blockQuote>' );
383383
} );
384384

385-
it.skip( 'delete all wrapped content and undo', () => {
385+
it( 'delete all wrapped content and undo', () => {
386386
john.setData( '[<paragraph>Foo</paragraph><paragraph>Bar</paragraph><paragraph>Abc</paragraph>]' );
387387
kate.setData( '<paragraph>[Foo</paragraph><paragraph>Bar</paragraph><paragraph>Ab]c</paragraph>' );
388388

0 commit comments

Comments
 (0)