fix: close the undo block without leaking buffer-local 'undolevels' into the global option - #12
Merged
Merged
Conversation
…nto the global option 'undolevels' is a global-local option, so the unscoped `let &undolevels=&undolevels` idiom reads the effective (buffer-local when set) value and writes it back as the GLOBAL value. Accepting a suggestion in a buffer with a local override (-1/0 from diffview/mason/neogit/suda/ nui panels or tmp-file guards) silently disabled undo for every buffer opened afterwards. Scope both sides to &g:undolevels: the block-closing side effect triggers on setting the option regardless of scope, so the split still works, and no value is ever copied or pinned. Fixes teocns#11
… global option Round 6 sets undolevels=-1 buffer-locally (as diffview/mason/neogit-style panel buffers do), accepts a suggestion, and asserts the global option is unchanged, then drops the local override. Against the pre-fix code the new assertion fails (got=-1, want=1000); with the &g: fix the full spec reports ALL PASS.
Owner
|
Thank you for your contribution |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #11.
Accepting a suggestion could copy a buffer-local
'undolevels'value into the global option and silently disable undo in every buffer afterwards. This patch keeps the undo-block split and never writes the global option.Root cause
do_accept()closes the current undo block with the documented vimscript idiom (:help undo-close-block):'undolevels'is a global-local option. The unscoped&undolevelson both sides of the assignment reads the effective value and writes it back as the global value. The effective value is the buffer-local value whenever one is set.A normal buffer can carry a persistent local
undolevelsof-1or0: commonsecure-style guards set it onCOMMIT_EDITMSG,MERGE_MSG,/tmp/*, and*.bakatBufReadPre. Plugins such as diffview.nvim, mason.nvim, neogit, and nui.nvim also set it, but onnofile/nowritepanels thatshould_attach()never accepts. An accept in a normal buffer with such an override sets globalundolevelsto that value. Every buffer without a local override then has undo disabled:ureports "Already at oldest change", and undo trees render empty.The fix
One token changes; both sides of the idiom are scoped to the global option:
Setting the option in any scope closes the undo block, so the split still happens. Only the value copy is gone.
Verification (Neovim 0.12.4)
uundolevels=-1, then accept, then read global-1(leak)undolevels=5, then accept, then change global5)test/flow_spec.luagains a Round 6 regression case. It setsundolevels=-1buffer-locally, accepts a suggestion, and asserts the global option is unchanged. Against the pre-fix code, the new assertion fails withgot=-1, want=1000. With this patch, the full spec reportsALL PASS.