Skip to content

Commit b08d3f3

Browse files
committed
for #380
1 parent 92918cf commit b08d3f3

File tree

1 file changed

+34
-12
lines changed

1 file changed

+34
-12
lines changed

lua/easycomplete/cmdline.lua

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function this.pum_redraw()
101101
if util.zizzing() then return end
102102
util.zizz()
103103
if redraw_queued then return end
104-
if vim.g.easycomplete_cmdline_pattern == '/' then
104+
if this.insearch() then
105105
redraw_queued = true
106106
-- 首次insearch匹配<s-tab>会导致匹配高亮渲染消失,这里做一下区分
107107
local cmdline = vim.fn.getcmdline()
@@ -158,6 +158,14 @@ function this.flush()
158158
this.pum_close()
159159
end
160160

161+
function this.insearch()
162+
if vim.g.easycomplete_cmdline_pattern == "/" or vim.g.easycomplete_cmdline_pattern == "?" then
163+
return true
164+
else
165+
return false
166+
end
167+
end
168+
161169
function this.pum_visible()
162170
return vim.fn["easycomplete#pum#visible"]()
163171
end
@@ -176,7 +184,7 @@ end
176184

177185
function this.pum_select_next()
178186
vim.fn['easycomplete#pum#next']()
179-
if vim.g.easycomplete_cmdline_pattern == '/' then
187+
if this.insearch() then
180188
return ""
181189
end
182190
util.zizz()
@@ -186,7 +194,7 @@ end
186194

187195
function this.pum_select_prev()
188196
vim.fn['easycomplete#pum#prev']()
189-
if vim.g.easycomplete_cmdline_pattern == '/' then
197+
if this.insearch() then
190198
return ""
191199
end
192200
util.zizz()
@@ -216,14 +224,29 @@ function this.bind_cmdline_event()
216224
group = augroup,
217225
pattern = ":",
218226
callback = function()
219-
vim.g.easycomplete_cmdline_pattern = ":"
227+
if vim.fn.getcmdtype() == ":" then
228+
vim.g.easycomplete_cmdline_pattern = ":"
229+
end
220230
end,
221231
})
232+
222233
vim.api.nvim_create_autocmd("CmdlineEnter", {
223234
group = augroup,
224235
pattern = "/",
225236
callback = function()
226-
vim.g.easycomplete_cmdline_pattern = "/"
237+
if vim.fn.getcmdtype() == "/" then
238+
vim.g.easycomplete_cmdline_pattern = "/"
239+
end
240+
end,
241+
})
242+
243+
vim.api.nvim_create_autocmd("CmdlineEnter", {
244+
group = augroup,
245+
pattern = "?",
246+
callback = function()
247+
if vim.fn.getcmdtype() == "?" then
248+
vim.g.easycomplete_cmdline_pattern = "?"
249+
end
227250
end,
228251
})
229252

@@ -250,8 +273,7 @@ function this.bind_cmdline_event()
250273
if vim.bo.filetype == 'help' then return end
251274
vim.g.easycomplete_cmdline_typing = 1
252275
local key_str = vim.api.nvim_replace_termcodes(keys, true, false, true)
253-
-- TODO 匹配模式闪烁问题没解决,先关闭
254-
if vim.g.easycomplete_cmdline_pattern == '/' and key_str ~= '\r' then
276+
if this.insearch() and key_str ~= '\r' then
255277
-- jayli 先关掉,继续调试
256278
-- do return end
257279
if util.zizzing() then
@@ -351,7 +373,7 @@ function this.cr_handler()
351373
this.do_path_complete()
352374
end
353375
end, 30)
354-
elseif vim.g.easycomplete_cmdline_pattern == "/" then
376+
elseif this.insearch() then
355377
local opr = this.get_tab_returing_opword()
356378
this.pum_close()
357379
vim.defer_fn(function()
@@ -378,7 +400,7 @@ this.REG_CMP_HANDLER = {
378400
-- 正在输入第一个命令
379401
pattern = "^[a-zA-Z0-9_]+$",
380402
get_cmp_items = function()
381-
if vim.g.easycomplete_cmdline_pattern == "/" then
403+
if this.insearch() then
382404
local typing_word = this.get_typing_word()
383405
local ret = this.get_buf_keywords(string.sub(typing_word, 1, 1))
384406
local ret = util.filter(ret, function(item)
@@ -398,7 +420,7 @@ this.REG_CMP_HANDLER = {
398420
"^[a-zA-Z0-9_]+%s+[glbwtvas]:%w-$", -- 命令输入完毕,输入 x:y 变量
399421
},
400422
get_cmp_items = function()
401-
if vim.g.easycomplete_cmdline_pattern == "/" then
423+
if this.insearch() then
402424
return {}
403425
end
404426
local cmd_name = this.get_guide_cmd()
@@ -448,7 +470,7 @@ this.REG_CMP_HANDLER = {
448470
"^[a-zA-Z0-9_]+%s+/$"
449471
},
450472
get_cmp_items = function()
451-
if vim.g.easycomplete_cmdline_pattern == "/" then
473+
if this.insearch() then
452474
return {}
453475
else
454476
return this.get_path_cmp_items()
@@ -462,7 +484,7 @@ this.REG_CMP_HANDLER = {
462484
"^[a-zA-Z0-9_]+%s+.*%\'[^\']-$",
463485
},
464486
get_cmp_items = function()
465-
if vim.g.easycomplete_cmdline_pattern == "/" then
487+
if this.insearch() then
466488
return {}
467489
end
468490
local typing_word = this.get_typing_word()

0 commit comments

Comments
 (0)