Skip to content

Commit 4e5553c

Browse files
committed
Fix line directly below insertion not incremented
The Vim help for `listener_add()` states this: > When lines are inserted the values are: > lnum line above which the new line is added > ... where line numbers are in the context of before the change. All lines greater than or equal to lnum should therefore be incremented, and not only those strictly greater.
1 parent 7bb72da commit 4e5553c

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

plugin/strip_trailing_whitespace.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ function s:Listener(bufnr, start, end, added, changes) abort
172172
" Adjust line numbers
173173
let b:root = s:Splay(b:root, a:start)
174174
if b:root isnot s:null
175-
if b:root.key > a:start
175+
if b:root.key >= a:start
176176
let b:root.key += a:added
177177
if b:root.left isnot s:null | let b:root.left.key -= a:added | endif
178178
elseif b:root.right isnot s:null

test/test.vim

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
1-
function Test_OneLineUnchanged() abort
1+
function s:TestEdits(original, EditCb, expected) abort
22
let fname = tempname()
3-
let contents = ['line1 ']
4-
call writefile(contents, fname)
3+
call writefile(a:original, fname)
54
silent execute 'edit' fname
5+
call a:EditCb()
66
silent write
7-
call assert_equal(['line1 '], readfile(fname))
7+
call assert_equal(a:expected, readfile(fname))
88
%bwipeout!
99
endfunction
1010

11+
function Test_OneLineUnchanged() abort
12+
function! s:EditCb() abort
13+
endfunction
14+
call s:TestEdits(['foo '], function('s:EditCb'), ['foo '])
15+
endfunction
16+
1117
function Test_OneLineChanged() abort
12-
let fname = tempname()
13-
let contents = ['line1 ']
14-
call writefile(contents, fname)
15-
silent execute 'edit' fname
16-
normal! rf
17-
silent write
18-
call assert_equal(['fine1'], readfile(fname))
19-
%bwipeout!
18+
function! s:EditCb() abort
19+
normal! rf
20+
endfunction
21+
call s:TestEdits(['line1 '], function('s:EditCb'), ['fine1'])
22+
endfunction
23+
24+
function Test_AddLineAboveChange() abort
25+
function! s:EditCb() abort
26+
normal! rzO
27+
endfunction
28+
call s:TestEdits(['foo '], function('s:EditCb'), ['', 'zoo'])
2029
endfunction

0 commit comments

Comments
 (0)