Skip to content

Commit 4e4c9df

Browse files
committed
remove tokenization if applied on an already tokenized string
1 parent 64046ec commit 4e4c9df

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

lua/telescope-live-grep-args/actions/tokenize.lua

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,33 @@ return function(opts)
5353
if opts.trim then
5454
prompt = vim.trim(prompt)
5555
end
56-
local tokens = {}
57-
-- TODO interpret two spaces or more as a literal space
58-
for token in prompt:gmatch("%S+") do
59-
table.insert(tokens, token)
56+
local already_tokenized = false
57+
for match in prompt:gmatch("%.%*") do
58+
already_tokenized = true
59+
break
6060
end
61+
if already_tokenized then
62+
local tokens = ""
63+
-- TODO The first match may not be in the same order as the original prompt
64+
for match in prompt:gmatch("[^|]+") do
65+
tokens = match:gsub("%.%*", " ")
66+
break
67+
end
68+
picker:set_prompt(tokens)
69+
else
70+
local tokens = {}
71+
-- TODO interpret two spaces or more as a literal space
72+
for token in prompt:gmatch("%S+") do
73+
table.insert(tokens, token)
74+
end
6175

62-
prompt = ""
63-
for combo in permutations(removeDuplicates(tokens)) do
64-
prompt = prompt .. "|" .. table.concat(combo, ".*")
65-
end
66-
prompt = prompt:sub(2)
76+
prompt = ""
77+
for combo in permutations(removeDuplicates(tokens)) do
78+
prompt = prompt .. "|" .. table.concat(combo, ".*")
79+
end
80+
prompt = prompt:sub(2)
6781

68-
picker:set_prompt(prompt)
82+
picker:set_prompt(prompt)
83+
end
6984
end
7085
end

0 commit comments

Comments
 (0)