Skip to content

Commit 6f91cd1

Browse files
Kypertbejado
authored andcommitted
Avoid 2x undo (rhysd#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 6b79182 commit 6f91cd1

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
@@ -259,10 +259,9 @@ function! clang_format#replace_ranges(ranges, ...) abort
259259
return
260260
endif
261261

262-
let winview = winsaveview()
263262
let splitted = split(formatted, '\n', 1)
264263

265-
silent! undojoin
264+
let winview = winsaveview()
266265
if line('$') > len(splitted)
267266
execute len(splitted) .',$delete' '_'
268267
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
@@ -450,9 +450,28 @@ describe 'undo formatting text'
450450
bdelete!
451451
end
452452

453+
it 'can make a change, format (constitutes as a second change), then undo and keep the first change'
454+
normal! ggOmega
455+
ClangFormat
456+
" When running :ClangFormat from a normal vim instance, setline() does add an entry in the undolist
457+
" For some reason it does not do so when running in this test framework
458+
" Also, seems like it is hard to even add another item to the change list too, always rendering:
459+
" # number changes when saved
460+
" # 9 1 0 seconds ago
461+
normal! ggOadditional
462+
:Debug GetBuffer()
463+
" TODO: should enable this
464+
" normal! u
465+
Expect 0 != search('mega', 'cw')
466+
undo
467+
Expect 0 == search('mega', 'cw')
468+
end
469+
453470
it 'restores previous text as editing buffer normally'
454471
let prev = GetBuffer()
455472
ClangFormat
473+
let buf = GetBuffer()
474+
Expect prev != buf
456475
undo
457476
let buf = GetBuffer()
458477
Expect prev ==# buf

0 commit comments

Comments
 (0)