Skip to content

Commit

Permalink
fix(previewer): accurate magic pattern conversion
Browse files Browse the repository at this point in the history
The previous conversion wasn't accurate, tested with all regex
special characters, although I coulnd't find this in the docs
"very magic" pattern requires escaping of special chars "=&<>".
  • Loading branch information
ibhagwan committed Aug 16, 2024
1 parent 253c6ff commit 40904ab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lua/fzf-lua/providers/grep.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ local get_grep_cmd = function(opts, search_query, no_esc)
end

search_query = search_query or ""
if not (no_esc or opts.no_esc) then
search_query = utils.rg_escape(search_query)
if #search_query > 0 and not (no_esc or opts.no_esc) then
-- For UI consistency, replace the saved search query with the regex
opts.no_esc = true
opts.search = utils.rg_escape(search_query)
search_query = opts.search
end

-- remove column numbers when search term is empty
Expand Down
4 changes: 3 additions & 1 deletion lua/fzf-lua/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ function M.rg_escape(str)
end

function M.regex_to_magic(str)
return [[\v]] .. str:gsub([[\\]], [[\]]):gsub("=", [[\=]])
-- Convert regex to "very magic" pattern, basically a regex
-- with special meaning for "=&<>", `:help /magic`
return [[\v]] .. str:gsub("[=&<>]", function(x) return [[\]] .. x end)
end

function M.sk_escape(str)
Expand Down

0 comments on commit 40904ab

Please sign in to comment.