fix(picker.actions): clamp cursor line when the buffer shrank - #2940
Open
truls27a wants to merge 1 commit into
Open
fix(picker.actions): clamp cursor line when the buffer shrank#2940truls27a wants to merge 1 commit into
truls27a wants to merge 1 commit into
Conversation
truls27a
force-pushed
the
fix/picker-jump-clamp-cursor
branch
from
August 24, 2026 04:42
64f0043 to
67faa96
Compare
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.
Description
M.jumprestores the cursor fromitem.pos, which the finder snapshotted when the picker opened: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 confirmM.jumpasks 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/testpasses.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)