Skip to content

fix(keymaps): Keep existing buffer-local mappings across source popups - #50

Merged
mhiro2 merged 2 commits into
mainfrom
fix/source-popup-keymap-restore
Oct 3, 2026
Merged

mhiro2 merged 2 commits into
mainfrom
fix/source-popup-keymap-restore

Conversation

@mhiro2

@mhiro2 mhiro2 commented Oct 3, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Source-mode popups no longer lose buffer-local mappings such as <C-j>, <C-w>h or <leader>os that were written with a different spelling than peekstack's keys.
  • Shadowed mappings are snapshotted with maparg() and restored with mapset(), keeping callbacks, expr, <SID> and script context.
  • Cleanup only touches the normal-mode keys the popup installed, even if other modes or mapleader change while it is open.

Changes

  • 086db74 : fix(keymaps): restore shadowed source buffer mappings as Neovim resolves them
    • Look up the mapping to shadow with Neovim's own key resolution instead of comparing raw lhs strings, so normalized forms (<C-J>, <C-W>h, expanded leader) are found.
    • Restore the exact mapping via mapset(), and take all snapshots before installing any popup key so aliases that resolve to the same keys stay intact.
    • Cover Ctrl, leader, <SID> and Lua callback mappings across close and WinLeave, and keep global mappings global.
  • 38c8638 : fix(keymaps): limit source popup cleanup to the keys it installed
    • Restore snapshots in normal mode only, so visual/operator-pending parts of a :map mapping changed during the popup are kept.
    • Delete by the lhs resolved at install time, so changing mapleader neither removes an unrelated mapping nor leaks the popup's own.

@mhiro2 mhiro2 self-assigned this Oct 3, 2026
@mhiro2 mhiro2 added the bug Something isn't working label Oct 3, 2026
mhiro2 added 2 commits October 3, 2026 09:09
…ves them

Source popups looked up the mapping to shadow by comparing lhs strings,
so <C-j>, <C-w>h and <leader>os never matched Neovim's normalized form
(<C-J>, <C-W>h, the expanded leader) and those buffer-local mappings
were lost after the popup closed or lost focus.

- Snapshot mappings with maparg() in the source buffer and restore them
  with mapset(), keeping callback, expr, <SID> and multi-mode mappings.
- Take every snapshot before installing any popup key and delete before
  restoring, so lhs spellings that resolve to the same keys stay intact.
- Cover Ctrl, leader, <SID> and Lua callback mappings across close and
  WinLeave, and leave global mappings global.
Restoring a whole :map snapshot reset visual and operator-pending
mappings that the popup never touched, discarding changes made while it
was open. Cleanup also re-resolved <leader> at close time, so changing
mapleader removed an unrelated mapping and leaked the popup's own.

- Restore snapshots in normal mode only.
- Remember the resolved lhs of each installed mapping and delete by it.
- Cover both cases, including closing while another buffer is current.
@mhiro2
mhiro2 force-pushed the fix/source-popup-keymap-restore branch from 6ff1bf9 to 38c8638 Compare October 3, 2026 00:09
@mhiro2
mhiro2 merged commit 151adbc into main Oct 3, 2026
3 checks passed
@mhiro2
mhiro2 deleted the fix/source-popup-keymap-restore branch October 3, 2026 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant