@@ -9,6 +9,9 @@ import Element from '../../src/model/element';
9
9
import Text from '../../src/model/text' ;
10
10
import Document from '../../src/model/document' ;
11
11
import TreeWalker from '../../src/model/treewalker' ;
12
+ import MergeDelta from '../../src/model/delta/mergedelta' ;
13
+ import MoveOperation from '../../src/model/operation/moveoperation' ;
14
+ import RemoveOperation from '../../src/model/operation/removeoperation' ;
12
15
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror' ;
13
16
import { jsonParseStringify } from '../../tests/model/_utils/utils' ;
14
17
@@ -1056,6 +1059,35 @@ describe( 'Range', () => {
1056
1059
expect ( transformed [ 0 ] . start . path ) . to . deep . equal ( [ 0 , 0 , 1 ] ) ;
1057
1060
expect ( transformed [ 0 ] . end . path ) . to . deep . equal ( [ 0 , 1 , 1 ] ) ;
1058
1061
} ) ;
1062
+
1063
+ // #1132.
1064
+ it ( 'merge delta has move operation that does not start from offset 0' , ( ) => {
1065
+ // This scenario is a test for a rare situation, that after some OT, a move operation in
1066
+ // merge delta does not start from 0 offset.
1067
+ //
1068
+ // It happens that move operation in merge delta becomes "do nothing move operation", something like:
1069
+ //
1070
+ // move range [ a, x ] - [ a, y ] to [ a, x ]
1071
+ // for example: move [ 0, 3 ] - [ 0, 6 ] -> [ 0, 3 ]
1072
+ //
1073
+ // This is a result of valid transformation and we need to check if range is properly transformed
1074
+ // when such unusual delta is generated.
1075
+ // For more see: https://github.com/ckeditor/ckeditor5-engine/pull/1133#issuecomment-329080668.
1076
+ //
1077
+ // For this test scenario assume: <p>foobar[]</p>, "bar" is moved between "o" and "b".
1078
+ // Expect state after transformation is that nothing has changed.
1079
+ const range = new Range ( new Position ( root , [ 0 , 6 ] ) , new Position ( root , [ 0 , 6 ] ) ) ;
1080
+
1081
+ const delta = new MergeDelta ( ) ;
1082
+ delta . addOperation ( new MoveOperation ( new Position ( root , [ 0 , 3 ] ) , 3 , new Position ( root , [ 0 , 3 ] ) , 0 ) ) ;
1083
+ delta . addOperation ( new RemoveOperation ( new Position ( root , [ 1 ] ) , 1 , new Position ( doc . graveyard , [ 0 ] ) , 1 ) ) ;
1084
+
1085
+ const transformed = range . getTransformedByDelta ( delta ) ;
1086
+
1087
+ expect ( transformed . length ) . to . equal ( 1 ) ;
1088
+ expect ( transformed [ 0 ] . start . path ) . to . deep . equal ( [ 0 , 6 ] ) ;
1089
+ expect ( transformed [ 0 ] . end . path ) . to . deep . equal ( [ 0 , 6 ] ) ;
1090
+ } ) ;
1059
1091
} ) ;
1060
1092
1061
1093
describe ( 'by WrapDelta' , ( ) => {
0 commit comments