Skip to content

fix(nvim): preserve list cursor position on picker resume#613

Open
KorigamiK wants to merge 2 commits into
dmtrKovalenko:mainfrom
KorigamiK:fix/resume-cursor-position
Open

fix(nvim): preserve list cursor position on picker resume#613
KorigamiK wants to merge 2 commits into
dmtrKovalenko:mainfrom
KorigamiK:fix/resume-cursor-position

Conversation

@KorigamiK

Copy link
Copy Markdown

Summary

Fixes #612.

Resuming a picker did not restore the selected list item — the highlight always reset to the first result.

restore_from_state restores state.cursor, then writes the saved query into the input buffer. The buffer's on_lines callback schedules on_input_change, which re-runs the search and unconditionally does S.cursor = 1, clobbering the restored cursor.

Fix

Suppress that single on_input_change during restore via a one-shot suppress_input_change flag. The snapshot already holds the exact items/filtered_items/cursor, so re-running the search on resume is both unnecessary and the source of the bug. Suppressing it preserves the restored cursor naturally and renders once, instead of relying on a second scheduled re-assert of the cursor.

Testing

  • Manually verified resume of both find_files and live_grep restores the previously selected entry, query, and preview for prompt_position top and bottom.

Copilot AI review requested due to automatic review settings June 18, 2026 21:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Resuming a picker wrote the saved query into the input buffer, whose
on_lines callback scheduled on_input_change. That re-ran the search and
reset the cursor to the first result, discarding the restored position.

Suppress that single on_input_change during restore so the snapshot's
items and cursor are kept verbatim, rendering once instead of relying on
a second scheduled re-assert.
Resuming a picker reset the selected entry to the first result. The saved
cursor was restored, but writing the query into the input buffer triggers
on_input_change, which re-runs the search and sets S.cursor = 1.

Re-running the search on resume is intentional (results may have changed
since close), so instead of suppressing it, thread the saved cursor
through: restore_from_state stashes it in pending_restore_cursor and the
re-search restores that position, clamped to the fresh result count.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resume does not restore the selected list item (cursor) position

2 participants