Skip to content

Commit fb4d1e1

Browse files
committed
Fix undo hunk
Fixes mhinz#345 When `new_count` is `0` it's a special case meaning that lines should be inserted after `new_line`, not instead of it. When you remove `line 2` from file: ``` line 1 line 2 line 3 line 4 ``` the diff looks line this: ```diff index 9c2a709..cbf7f40 100644 --- a/test.txt +++ b/test.txt @@ -2 +1,0 @@ line 1 -line 2 ``` It means `line 2` in `undo` should be inserted below line 1 (`new_line`) and before it was inserted after line 0 (`new_line - 1`).
1 parent 98c693f commit fb4d1e1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

autoload/sy/repo.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ function! s:undo_hunk(sy, vcs, diff) abort
413413
return
414414
endif
415415

416-
let [_old_line, _old_count, new_line, _new_count] = sy#sign#parse_hunk(header)
416+
let [_old_line, _old_count, new_line, new_count] = sy#sign#parse_hunk(header)
417417

418418
for line in hunk
419419
let op = line[0]
@@ -425,7 +425,7 @@ function! s:undo_hunk(sy, vcs, diff) abort
425425
endif
426426
let new_line += 1
427427
elseif op == '-'
428-
call append(new_line-1, text)
428+
call append(new_count == 0 ? new_line : new_line - 1, text)
429429
let new_line += 1
430430
elseif op == '+'
431431
if text != getline(new_line)

0 commit comments

Comments
 (0)