fix(preview): drop vim.pesc on grep highlight needle (#630)#635
Closed
gustav-fff wants to merge 1 commit into
Closed
fix(preview): drop vim.pesc on grep highlight needle (#630)#635gustav-fff wants to merge 1 commit into
gustav-fff wants to merge 1 commit into
Conversation
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
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 #630
Root cause
lua/fff/location_utils.lua:207runsvim.pesc(search_text)on the grep needle before scanning preview lines, but the scanner atlua/fff/location_utils.lua:224callsstring.find(search_line, search_pat, start_pos, true)withplain=true. Withplain=truethe 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 intostring.find(..., true)directly. Smart-case lowering is preserved.Steps to reproduce
git checkout origin/main nvim ~/some/repoInside Neovim:
:lua require('fff').find_files()then toggle to grep mode (default<C-g>), submodeplainorregex.., e.g.foo.baror1.0orvim.api.Expected: every occurrence of
foo.barin the preview window is highlighted withIncSearch.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
string.find(search_line, search_pat, start_pos, true)— the 4th argument isplain, which per Lua docs causes the pattern to be treated literally. Combined withvim.pesc, every metachar yields a needle that cannot match real content.vim.apion this repo, pre-fix: no preview highlights. Post-fix: allvim.apioccurrences in the visible preview window highlighted.Automated triage via Gustav. Honk-Honk 🪿