Skip to content

fix(preview): keep cursor on match when paging with <C-d>/<C-u>#556

Merged
dmtrKovalenko merged 2 commits into
mainfrom
triage-bot/issue-555
Jun 2, 2026
Merged

fix(preview): keep cursor on match when paging with <C-d>/<C-u>#556
dmtrKovalenko merged 2 commits into
mainfrom
triage-bot/issue-555

Conversation

@gustav-fff
Copy link
Copy Markdown
Collaborator

Closes #555 (step 1 only)

Root cause

preview.scroll() in lua/fff/file_picker/preview.lua:682 set the cursor to {new_offset + 1, 0} and ran zt. The cursor (and therefore the cursorline / location highlight) tracked the viewport top instead of the match line. Pressing <C-d>/<C-u> made the highlighted line jump away from the actual match.

Fix

Page the viewport without moving the cursor. Use vim.fn.winrestview({ topline = topline }) instead of nvim_win_set_cursor + zt. Cursor stays parked on the match line set by scroll_to_line(), so the highlight stays put while content scrolls past it.

Steps to reproduce

git checkout main
make build
nvim
" :FFFFind, type a query, focus a result with location info (e.g. grep mode),
" then press <C-d>/<C-u> in the picker to scroll preview.
" Before fix: cursorline / IncSearch highlight jumps with viewport top.
" After fix: cursorline stays on the match; only viewport scrolls.

How verified

Local manual run on ~/dev/lightsource in grep mode — <C-d>/<C-u> scrolls preview viewport while highlighted match stays anchored. No change to navigation between picker results (different code path, scroll_to_line / apply_location_highlighting).

Step 2 (highlight ALL matches in file) — NOT in this PR

Out of scope for the auto-fix budget. It needs a Rust pass that scans the full file for the query (fuzzy + exact) and returns every match's byte range, then highlight_grep_matches (lua/fff/location_utils.lua:147) needs to consume that list instead of the current per-target-line fuzzy_match_ranges + ±200 line plain-text scan. @dmtrKovalenko this needs scoping — happy to take it on once the shape (Rust API + perf budget for whole-file scan during preview) is decided.

Automated triage via Gustav. Honk-Honk 🪿

preview.scroll moved the cursor to the new topline, which dragged the
location highlight / cursorline away from the matched line. Page the
viewport with winrestview({topline=...}) instead so cursor stays parked
on the match.

Refs #555
@dmtrKovalenko dmtrKovalenko merged commit 394a4dc into main Jun 2, 2026
46 checks passed
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.

When using <C-d> and <C-u> in the preview mode highlight is jupming as wel

2 participants