File tree Expand file tree Collapse file tree 2 files changed +6
-2
lines changed Expand file tree Collapse file tree 2 files changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -641,7 +641,11 @@ function fix_cursor (diffs, cursor_pos) {
641
641
var d = ndiffs [ cursor_pointer ] ;
642
642
var d_next = ndiffs [ cursor_pointer + 1 ] ;
643
643
644
- if ( d [ 0 ] !== DIFF_EQUAL ) {
644
+ if ( d == null ) {
645
+ // Text was deleted from end of original string,
646
+ // cursor is now out of bounds in new string
647
+ return diffs ;
648
+ } else if ( d [ 0 ] !== DIFF_EQUAL ) {
645
649
// A modification happened at the cursor location.
646
650
// This is the expected outcome, so we can return the original diff.
647
651
return diffs ;
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ for(var i = 0; i < ITERATIONS; ++i) {
38
38
39
39
console . log ( 'Running tests *with* cursor information' ) ;
40
40
for ( var i = 0 ; i < ITERATIONS ; ++ i ) {
41
- var cursor_pos = Math . floor ( random ( ) * strings [ i ] . length ) ;
41
+ var cursor_pos = Math . floor ( random ( ) * strings [ i ] . length + 1 ) ;
42
42
var diffs = diff ( strings [ i ] , strings [ i + 1 ] , cursor_pos ) ;
43
43
var patch = googlediff . patch_make ( strings [ i ] , strings [ i + 1 ] , diffs ) ;
44
44
var expected = googlediff . patch_apply ( patch , strings [ i ] ) [ 0 ] ;
You can’t perform that action at this time.
0 commit comments