File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1075,10 +1075,12 @@ export class Delta {
10751075 }
10761076 while ( currNode != null && currNode . length <= remainingLen ) {
10771077 list . pushEnd ( cpy . children , currNode . clone ( ) )
1078+ remainingLen -= currNode . length
10781079 currNode = currNode . next
10791080 }
10801081 if ( currNode != null && remainingLen > 0 ) {
10811082 list . pushEnd ( cpy . children , currNode . clone ( 0 , remainingLen ) )
1083+ remainingLen -= math . min ( currNode . length , remainingLen )
10821084 }
10831085 cpy . childCnt = slicedLen - remainingLen
10841086 // @ts -ignore
@@ -2247,11 +2249,12 @@ export const diff = (d1, d2) => {
22472249 const cd = cdiff [ i ]
22482250 cd . remove = isContent . slice ( cd . index , cd . index + cd . remove . length )
22492251 cd . insert = shouldContent . slice ( cd . index + adj , cd . index + adj + cd . insert . length )
2250- adj += cd . remove . length - cd . insert . length
2252+ adj += cd . insert . length - cd . remove . length
22512253 }
22522254 for ( let i = 0 , lastIndex = 0 ; i < cdiff . length ; i ++ ) {
22532255 const cd = cdiff [ i ]
22542256 d . retain ( cd . index - lastIndex )
2257+ lastIndex = cd . index
22552258 let cdii = 0
22562259 let cdri = 0
22572260 // try to match as much content as possible, preferring to skip over non-deltas
Original file line number Diff line number Diff line change @@ -710,3 +710,13 @@ export const testDeltaDiffWithFormatting2 = () => {
710710 const diff = delta . diff ( d1 , d2 )
711711 t . compare ( diff , delta . create ( ) . retain ( 5 ) . insert ( ' ' ) . insert ( 'world' , { bold : true } ) )
712712}
713+
714+ export const testDeltaDiffIssue1 = ( ) => {
715+ const stateA = delta . create ( ) . insert ( [ delta . create ( 'paragraph' ) . set ( 'ychange' , null ) . insert ( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) ] )
716+ const stateB = delta . create ( ) . insert ( [ delta . create ( 'paragraph' ) . set ( 'ychange' , null ) . insert ( 'ABCDE123FGHIJKLMNOPQRSTUVWXYZ2sawfa' ) ] )
717+ const expectedDiff = delta . create ( ) . modify ( delta . create ( ) . retain ( 5 ) . insert ( '123' ) . retain ( 21 ) . insert ( '2sawfa' ) )
718+ const diffResult = delta . diff ( stateA , stateB )
719+ const synced = delta . clone ( stateA ) . apply ( diffResult )
720+ t . assert ( synced . equals ( stateB ) )
721+ t . assert ( expectedDiff . equals ( diffResult ) )
722+ }
You can’t perform that action at this time.
0 commit comments