fix(keymaps): properly clean up keymaps on close (fixes #211)#226
Merged
esmuellert merged 3 commits intomainfrom Feb 5, 2026
Merged
fix(keymaps): properly clean up keymaps on close (fixes #211)#226esmuellert merged 3 commits intomainfrom
esmuellert merged 3 commits intomainfrom
Conversation
Fixes #211 - Keymaps not restored properly after quitting CodeDiff The issue was that when navigating files with J/K, new buffers would get keymaps set but old buffers weren't tracked. On close, only current buffers had keymaps deleted, leaving orphaned buffer-local keymaps that shadowed user's global keymaps. Solution: - Track all buffers in sess.keymap_buffers when keymaps are set - On close, delete keymaps from ALL tracked buffers This also reverts the previous save/restore approach (commit 9a18715) which was unnecessarily complex and didn't fix the actual issue.
These keymaps are already set via view/keymaps.lua:setup_all_keymaps() which uses set_tab_keymap to set them on all buffers including explorer and history panels. No need to set them again in panel-specific keymaps.
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.
Summary
Fixes #211 - Keymaps not restored properly after quitting
:CodeDiffwithqProblem
When users configured custom keymaps (e.g.,
J,Kfornext_file/prev_file) and navigated files, the keymaps would be set on new buffers but old buffers weren't tracked. On close, only current buffers had keymaps deleted, leaving orphaned buffer-local keymaps that shadowed user's global keymaps.Solution
Revert complex save/restore logic (commit 9a18715) - This approach was unnecessarily complex and didn't fix the actual issue. Buffer-local keymaps shadow global ones, so we just need to delete our keymaps (not save/restore).
Track all buffers - Store all buffers that ever had keymaps set in
sess.keymap_buffersClean up all tracked buffers - On close, delete keymaps from ALL tracked buffers, not just current ones
Remove duplicate keymap definitions -
next_file/prev_filewere defined in bothview/keymaps.luaandexplorer/keymaps.lua/history/keymaps.lua. Now only defined once viaset_tab_keymap.Changes
lua/codediff/ui/lifecycle/accessors.lua: Track buffers inkeymap_buffers, clean up all on closelua/codediff/ui/explorer/keymaps.lua: Remove duplicatenext_file/prev_filelua/codediff/ui/history/keymaps.lua: Remove duplicatenext_file/prev_filetests/keymap_restore_spec.lua: Removed (tested reverted functionality)Testing
All existing tests pass.