Skip to content

fix(picker.actions): clamp cursor line when the buffer shrank - #2940

Open
truls27a wants to merge 1 commit into
folke:mainfrom
truls27a:fix/picker-jump-clamp-cursor
Open

fix(picker.actions): clamp cursor line when the buffer shrank#2940
truls27a wants to merge 1 commit into
folke:mainfrom
truls27a:fix/picker-jump-clamp-cursor

Conversation

@truls27a

Copy link
Copy Markdown

Description

M.jump restores the cursor from item.pos, which the finder snapshotted when the picker opened:

vim.api.nvim_win_set_cursor(win, { pos[1], pos[2] })

If the buffer has fewer lines by the time the pick is confirmed, this raises Invalid cursor line: out of range.

Terminal buffers hit it regularly. A terminal buffer has one line per row of the window showing it, and previewing a loaded buffer puts the real buffer in the preview window (picker/preview.lua:110), which resizes the pty down to the preview's height. The position was captured before that, so on confirm M.jump asks for a line the shrunken buffer no longer has.

This clamps the line to the buffer's last line. The column already gets clamped by nvim_win_set_cursor.

Tested with the repro from #2939, and by driving the buffers picker over a buffer that shrinks while the picker is open: before, actions.lua:149: Invalid cursor line: out of range; after, the jump lands on the last line. ./scripts/test passes.

One thing I did not do, since it is a behaviour choice: for buftype == "terminal" it may be better to skip the cursor restore altogether, because the clamped line stops meaning anything as soon as the pty resizes back. Happy to change it to that.

Related Issue(s)

@github-actions github-actions Bot added picker size/s Small PR (<10 lines changed) labels Aug 24, 2026
@truls27a
truls27a force-pushed the fix/picker-jump-clamp-cursor branch from 64f0043 to 67faa96 Compare August 24, 2026 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

picker size/s Small PR (<10 lines changed)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(picker): jumping to a terminal buffer fails with "Invalid cursor line: out of range"

1 participant