Skip to content

Commit c6cc7d2

Browse files
committed
Avoid 2x undo (#98)
Kind of hard to follow the history of this, but currently (NVIM v0.5.0-427-g1f56f9a4b) it seems like this undojoin makes some unexpected behaviour for the user. Unable to tell what-else is unlocked by removing it, so let's try without it for a while.
1 parent 2476aa4 commit c6cc7d2

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

autoload/clang_format.vim

+1-2
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ function! clang_format#replace(line1, line2, ...) abort
237237
return
238238
endif
239239

240-
let winview = winsaveview()
241240
let splitted = split(formatted, '\n', 1)
242241
if getline(a:line1, a:line2) ==# splitted[a:line1-1:a:line2-1]
243242
if g:clang_format#praise
@@ -252,7 +251,7 @@ function! clang_format#replace(line1, line2, ...) abort
252251
echo ""
253252
endif
254253

255-
silent! undojoin
254+
let winview = winsaveview()
256255
if line('$') > len(splitted)
257256
execute len(splitted) .',$delete' '_'
258257
endif

test/VimFlavor.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
kana/vim-operator-user (0.1.0)
2-
kana/vim-vspec (1.6.1)
2+
kana/vim-vspec (1.9.0)
33
rhysd/vim-vspec-matchers (0.0.4)

test/t/clang_format_spec.vim

+19
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,28 @@ describe 'undo formatting text'
459459
bdelete!
460460
end
461461

462+
it 'can make a change, format (constitutes as a second change), then undo and keep the first change'
463+
normal! ggOmega
464+
ClangFormat
465+
" When running :ClangFormat from a normal vim instance, setline() does add an entry in the undolist
466+
" For some reason it does not do so when running in this test framework
467+
" Also, seems like it is hard to even add another item to the change list too, always rendering:
468+
" # number changes when saved
469+
" # 9 1 0 seconds ago
470+
normal! ggOadditional
471+
:Debug GetBuffer()
472+
" TODO: should enable this
473+
" normal! u
474+
Expect 0 != search('mega', 'cw')
475+
undo
476+
Expect 0 == search('mega', 'cw')
477+
end
478+
462479
it 'restores previous text as editing buffer normally'
463480
let prev = GetBuffer()
464481
ClangFormat
482+
let buf = GetBuffer()
483+
Expect prev != buf
465484
undo
466485
let buf = GetBuffer()
467486
Expect prev ==# buf

0 commit comments

Comments
 (0)