Skip to content

fix(preview): drop vim.pesc on grep highlight needle (#630)#635

Closed
gustav-fff wants to merge 1 commit into
mainfrom
triage-bot/issue-630
Closed

fix(preview): drop vim.pesc on grep highlight needle (#630)#635
gustav-fff wants to merge 1 commit into
mainfrom
triage-bot/issue-630

Conversation

@gustav-fff

Copy link
Copy Markdown
Collaborator

Closes #630

Root cause

lua/fff/location_utils.lua:207 runs vim.pesc(search_text) on the grep needle before scanning preview lines, but the scanner at lua/fff/location_utils.lua:224 calls string.find(search_line, search_pat, start_pos, true) with plain=true. With plain=true the needle is treated as a literal byte sequence, so the escape turns . into %. and the scanner then looks for the two literal bytes % . in content — which never appears in normal source code. Same failure mode for every other Lua-pattern metachar (-, (, ), +, *, ?, [, ], ^, $, %). Single-word queries without metachars look fine, multi-word queries that happen to contain a . (e.g. file extensions, version strings, member access) lose preview highlighting entirely.

Fix

Drop vim.pesc. Pass the raw needle into string.find(..., true) directly. Smart-case lowering is preserved.

Steps to reproduce

git checkout origin/main
nvim ~/some/repo

Inside Neovim:

  1. :lua require('fff').find_files() then toggle to grep mode (default <C-g>), submode plain or regex.
  2. Type a query containing a ., e.g. foo.bar or 1.0 or vim.api.
  3. Move cursor to a result whose preview line contains the literal string.

Expected: every occurrence of foo.bar in the preview window is highlighted with IncSearch.
Actual: no preview highlights at all (the list row itself still shows the match because that path goes through Rust's match_byte_offsets, not this Lua scanner).

A single-token query without metachars (e.g. foo) highlights correctly, confirming the path works and only the escaping is wrong.

How verified

  • Read the scan loop: string.find(search_line, search_pat, start_pos, true) — the 4th argument is plain, which per Lua docs causes the pattern to be treated literally. Combined with vim.pesc, every metachar yields a needle that cannot match real content.
  • Manual repro in nvim with query vim.api on this repo, pre-fix: no preview highlights. Post-fix: all vim.api occurrences in the visible preview window highlighted.

Automated triage via Gustav. Honk-Honk 🪿

string.find runs with plain=true, so escaping turns '.' into '%.' and
the literal scanner then looks for the two bytes '%.' — missing every
real dot in content. Pass the raw needle through.

Closes #630
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.

[Bug]: File preview highlight not work on multi word query

2 participants