Skip to content

Commit

Permalink
Avoid 2x undo (#98)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Kypert committed Apr 18, 2020
1 parent 276a9e1 commit 24aef89
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
3 changes: 1 addition & 2 deletions autoload/clang_format.vim
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ function! clang_format#replace(line1, line2, ...) abort
return
endif

let winview = winsaveview()
let splitted = split(formatted, '\n', 1)
if getline(a:line1, a:line2) ==# splitted[a:line1-1:a:line2-1]
if g:clang_format#praise
Expand All @@ -247,7 +246,7 @@ function! clang_format#replace(line1, line2, ...) abort
return
endif

silent! undojoin
let winview = winsaveview()
if line('$') > len(splitted)
execute len(splitted) .',$delete' '_'
endif
Expand Down
2 changes: 1 addition & 1 deletion test/VimFlavor.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
kana/vim-operator-user (0.1.0)
kana/vim-vspec (1.6.1)
kana/vim-vspec (1.9.0)
rhysd/vim-vspec-matchers (0.0.4)
19 changes: 19 additions & 0 deletions test/t/clang_format_spec.vim
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,28 @@ describe 'undo formatting text'
bdelete!
end

it 'can make a change, format (constitutes as a second change), then undo and keep the first change'
normal! ggOmega
ClangFormat
" When running :ClangFormat from a normal vim instance, setline() does add an entry in the undolist
" For some reason it does not do so when running in this test framework
" Also, seems like it is hard to even add another item to the change list too, always rendering:
" # number changes when saved
" # 9 1 0 seconds ago
normal! ggOadditional
:Debug GetBuffer()
" TODO: should enable this
" normal! u
Expect 0 != search('mega', 'cw')
undo
Expect 0 == search('mega', 'cw')
end

it 'restores previous text as editing buffer normally'
let prev = GetBuffer()
ClangFormat
let buf = GetBuffer()
Expect prev != buf
undo
let buf = GetBuffer()
Expect prev ==# buf
Expand Down

0 comments on commit 24aef89

Please sign in to comment.