Repository navigation
fix(nvim): keep cursor position when picker closes from insert mode (#968) - #969
Conversation
Walkthrough
Merge Risk:
|
There was a problem hiding this comment.
🔇 Additional comments: 1
lua/fff/picker_ui/layout_manager.lua-31-32: 1
31-32:Minor · Functional Correctness · Quick win
⚠️ Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.Preserve cursor moves made by
FFFClosehandlers.If an
FFFClosehandler moves the cursor within the return window’s buffer, this callback restores the earlier position when Insert mode ends. The window and buffer checks do not distinguish that move from thestopinsertshift. Limit restoration to the shift caused by leaving Insert mode.FFFCloseruns after this callback is registered at Line 168;ModeChangedruns after the mode changes. (neovim.io)

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
e0d5abb2-e974-46f6-965b-7e8670aabbf2
Files selected for processing: 1-
lua/fff/picker_ui/layout_manager.lua
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
-
Closes #968
Root cause
M.close()runsstopinsert(lua/fff/picker_ui/layout_manager.lua:81), but this is deferred until mapping returns. Floats close first, so Insert mode ends in original window and<Esc>semantics move its cursor one cell left. This hits every close from insert mode: vim-mode<C-c>(ui_creator.lua:359), and default-mode<Esc>too. Vim-mode<Esc><Esc>is fine because close happens from normal mode.Fix
When
close()runs in insert mode, remember cursor of window we return to and restore it on one-shotModeChanged i:*, but only if window still shows same buffer. This fires before scheduled file-open inselect(), so jump locations are not touched.Steps to reproduce
Inside nvim:
Expected
[1, 7], actual onmain:[1, 6]. Same withprompt_vim_mode = falseand<Esc>.Headless version (no UI needed):
How verified
Same headless RPC harness, before -> after:
<C-c>:[1,6]->[1,7]<Esc>:[1,6]->[1,7]<Esc><Esc>,<Esc>q:[1,7]both, unchangedö, byte col 9): position keptlive_grepselect in same buffer (line 2):[2,13]both, location jump unchangedb.txtat[1,1], unchangedmake test-lua: 11 specs, 0 failedstylua --check: cleanmake test-lua-snap: same 16 local snapshot diffs with and without this change (local ranking differs), not caused by itAutomated triage via Gustav. Honk-Honk 🪿
Summary by CodeRabbit