Skip to content

Commit dc896c3

Browse files
committed
Fix added lines not being checked
Need to account for `a:added` in the listener when checking which lines had trailing whitespace added to them, since the range `a:start` to `a:end` is in the context of before the change.
1 parent f211049 commit dc896c3

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

plugin/strip_trailing_whitespace.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function StripTrailingWhitespaceListener(bufnr, start, end, added, changes) abor
204204
endif
205205

206206
" (Re-)Add lines in range with trailing whitespace
207-
for lnum in range(a:start, a:end - 1)
207+
for lnum in range(a:start, a:end + a:added - 1)
208208
let has_trailing_ws = getline(lnum) =~# '\s$'
209209
if has_trailing_ws
210210
call s:Put(lnum)

test/test.vim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ function Test_AddLineAboveChange() abort
2727
call s:TestEdits(['foo '], function('s:EditCb'), ['', 'zoo'])
2828
endfunction
2929

30+
function Test_DeleteAndPut() abort
31+
function! s:EditCb() abort
32+
normal! j2ddP
33+
endfunction
34+
call s:TestEdits(['first ', 'second ', 'third ', 'forth '], function('s:EditCb'), ['first ', 'second', 'third', 'forth '])
35+
endfunction
36+
3037
function Test_AbleToDisable() abort
3138
function! s:EditCb() abort
3239
let b:strip_trailing_whitespace_enabled = 0

0 commit comments

Comments
 (0)