summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorelianiva <dicha.arkana03@gmail.com>2021-01-03 21:07:37 +0700
committerGitHub <noreply@github.com>2021-01-03 15:07:37 +0100
commit88ebcaab10681e9b12bbf1c38719ae3d48d81f4d (patch)
treec2e56edf17a41cbf5d8edf18b13cffd022d07c34 /lua
parentc3806f46b920f53b32e417f8c586b8bb3ed0d95e (diff)
fix: escape chars instead of resetting the prompt (#379)
Diffstat (limited to 'lua')
-rw-r--r--lua/telescope/builtin/files.lua15
1 files changed, 14 insertions, 1 deletions
diff --git a/lua/telescope/builtin/files.lua b/lua/telescope/builtin/files.lua
index f2d84fd..d8175e2 100644
--- a/lua/telescope/builtin/files.lua
+++ b/lua/telescope/builtin/files.lua
@@ -11,6 +11,17 @@ local flatten = vim.tbl_flatten
local files = {}
+local escape_chars = function(string)
+ return string.gsub(string, "[%(|%)|\\|%[|%]|%-|%{%}|%?|%+|%*]", {
+ ["\\"] = "\\\\", ["-"] = "\\-",
+ ["("] = "\\(", [")"] = "\\)",
+ ["["] = "\\[", ["]"] = "\\]",
+ ["{"] = "\\{", ["}"] = "\\}",
+ ["?"] = "\\?", ["+"] = "\\+",
+ ["*"] = "\\*",
+ })
+end
+
files.live_grep = function(opts)
local live_grepper = finders.new_job(function(prompt)
-- TODO: Probably could add some options for smart case and whatever else rg offers.
@@ -19,7 +30,7 @@ files.live_grep = function(opts)
return nil
end
- if string.match(prompt, "[\\|%(%)]") then prompt = "" end
+ prompt = escape_chars(prompt)
return flatten { conf.vimgrep_arguments, prompt }
end,
@@ -41,6 +52,8 @@ files.grep_string = function(opts)
-- TODO: This should probably check your visual selection as well, if you've got one
local search = opts.search or vim.fn.expand("<cword>")
+ search = escape_chars(search)
+
opts.entry_maker = opts.entry_maker or make_entry.gen_from_vimgrep(opts)
opts.word_match = opts.word_match or nil