fix(preview): keep cursor on match when paging with <C-d>/<C-u>#556
Merged
Conversation
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
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.
Closes #555 (step 1 only)
Root cause
preview.scroll()inlua/fff/file_picker/preview.lua:682set the cursor to{new_offset + 1, 0}and ranzt. The cursor (and therefore thecursorline/ 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 ofnvim_win_set_cursor + zt. Cursor stays parked on the match line set byscroll_to_line(), so the highlight stays put while content scrolls past it.Steps to reproduce
How verified
Local manual run on
~/dev/lightsourcein 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-linefuzzy_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 🪿