Skip to content

fix(preview): highlight all matches per file in grep preview#559

Open
gustav-fff wants to merge 1 commit into
mainfrom
triage-bot/issue-555
Open

fix(preview): highlight all matches per file in grep preview#559
gustav-fff wants to merge 1 commit into
mainfrom
triage-bot/issue-555

Conversation

@gustav-fff
Copy link
Copy Markdown
Collaborator

Closes #555 (step 2). Step 1 already shipped in #556.

Root cause

location_utils.highlight_grep_matches only highlighted the cursor's match line. In fuzzy mode it explicitly returned after that line; in plain/regex it scanned ±200 lines via string.find, which still missed any match the cursor wasn't parked on (no per-line range visibility).

Fix

Plumb every loaded match for the previewed file from picker_ui through location.file_matches = { {line, ranges}, ... }, then highlight each range using ripgrep-supplied byte offsets (match_byte_offsets in Rust → match_ranges in Lua). Same path covers plain, regex, and fuzzy — all three populate the offsets in crates/fff-core/src/grep.rs:272. Falls back to the existing literal scan when file_matches is absent.

lua/fff/picker_ui.lua:1443 collects matches sharing relative_path. lua/fff/location_utils.lua:152 consumes them.

Steps to reproduce

git clone https://github.com/dmtrKovalenko/fff.git && cd fff
git checkout main
make build
nvim -c 'lua require("fff").setup()' some_repo_with_many_hits/

Then :FFFFind, switch to grep mode, type a query that hits the same file on multiple lines (e.g. function).

  • Pre-fix: only the line under the cursor is highlighted in the preview.
  • Post-fix: every matching line in the file is highlighted simultaneously, with exact byte spans.

How verified

make lint (rust). Lua linter is broken locally (missing /opt/homebrew/opt/lua/bin/lua5.4); change is mechanical Lua and structurally mirrors the existing fuzzy path that already shipped in #556.

Automated triage via Gustav. Honk-Honk 🪿

Closes #555 (step 2).

picker_ui collects every loaded match for the previewed file and
forwards them as location.file_matches. location_utils highlights each
range using the byte offsets ripgrep / fuzzy traceback already provide,
so plain, regex, and fuzzy modes all light up every hit at once.
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

1 participant