Skip to content

Commit d4fd6f0

Browse files
committed
search result fixed
1 parent 0b5bfb9 commit d4fd6f0

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

lua/easycomplete/cmdline.lua

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ local console = util.console
55
local cmdline_start_cmdpos = 0
66
local old_cmdline = ""
77
local pum_noselect = vim.g.easycomplete_pum_noselect
8+
-- 把 firstcomplete 匹配到的单词列表缓存起来
9+
local search_cmp_cache = {}
810
local redraw_queued = false
911
local last_redraw = false
1012
local this = {}
@@ -142,6 +144,7 @@ function this.flush()
142144
vim.g.easycomplete_cmdline_typing = 0
143145
cmdline_start_cmdpos = 0
144146
last_redraw = false
147+
search_cmp_cache = {}
145148
this.pum_close()
146149
end
147150

@@ -381,11 +384,25 @@ end
381384

382385
function this.get_normal_search_cmp()
383386
local typing_word = this.get_typing_word()
384-
local ret = this.get_buf_keywords(string.sub(typing_word, 1, 1))
385-
local ret = util.filter(ret, function(item)
386-
return string.lower(string.sub(item, 1, 1)) == string.lower(string.sub(typing_word, 1, 1))
387-
end)
388-
return ret
387+
local word_list = {}
388+
if #typing_word >=2 and #search_cmp_cache >= 1 then
389+
word_list = search_cmp_cache
390+
elseif #typing_word == 1 then
391+
word_list = this.get_buf_keywords(typing_word)
392+
search_cmp_cache = word_list
393+
end
394+
if #word_list > 200 then
395+
word_list = util.filter(word_list, function(item)
396+
local lower_sub_word = string.lower(string.sub(item, 1, 5))
397+
if string.find(lower_sub_word, string.lower(string.sub(typing_word, 1, 1))) then
398+
return true
399+
else
400+
return false
401+
end
402+
end)
403+
end
404+
console(#word_list)
405+
return word_list
389406
end
390407

391408
-- MAIN ROUTER

0 commit comments

Comments
 (0)