This commit is contained in:
hrsh7th
2021-10-16 22:09:01 +09:00
parent ebe040b1a9
commit f0a6cca5b9
4 changed files with 14 additions and 9 deletions

View File

@@ -162,10 +162,9 @@ core.on_change = function(self, event)
self:autoindent(event, function() self:autoindent(event, function()
local ctx = self:get_context({ reason = types.cmp.ContextReason.Auto }) local ctx = self:get_context({ reason = types.cmp.ContextReason.Auto })
debug.log(('ctx: `%s`'):format(ctx.cursor_before_line)) debug.log(('ctx: `%s`'):format(ctx.cursor_before_line))
if ctx:changed(ctx.prev_context) then if ctx:changed(ctx.prev_context) then
self.view:redraw() self.view:on_change()
debug.log('changed') debug.log('changed')
if vim.tbl_contains(config.get().completion.autocomplete or {}, event) then if vim.tbl_contains(config.get().completion.autocomplete or {}, event) then
@@ -262,6 +261,9 @@ core.filter = async.throttle(
if not misc.is_suitable_mode() then if not misc.is_suitable_mode() then
return return
end end
if self.view:get_active_entry() ~= nil then
return
end
local ctx = self:get_context() local ctx = self:get_context()
-- To wait for processing source for that's timeout. -- To wait for processing source for that's timeout.

View File

@@ -36,9 +36,9 @@ view.ready = function(self)
return self:_get_entries_view():ready() return self:_get_entries_view():ready()
end end
---Redraw menu. ---OnChange handler.
view.redraw = function(self) view.on_change = function(self)
self:_get_entries_view():redraw() self:_get_entries_view():on_change()
end end
---Open menu ---Open menu

View File

@@ -87,8 +87,11 @@ custom_entries_view.ready = function()
return vim.fn.pumvisible() == 0 return vim.fn.pumvisible() == 0
end end
custom_entries_view.redraw = function() custom_entries_view.on_change = function(self)
-- noop if self:visible() and self:get_active_entry() then
self.entries_win:option('cursorline', false)
vim.api.nvim_win_set_cursor(self.entries_win.win, { 1, 1 })
end
end end
custom_entries_view.open = function(self, offset, entries) custom_entries_view.open = function(self, offset, entries)
@@ -143,7 +146,6 @@ custom_entries_view.open = function(self, offset, entries)
end end
local delta = cursor[2] + 1 - self.offset local delta = cursor[2] + 1 - self.offset
self.entries_win:option('cursorline', false)
self.entries_win:open({ self.entries_win:open({
relative = 'editor', relative = 'editor',
style = 'minimal', style = 'minimal',
@@ -153,6 +155,7 @@ custom_entries_view.open = function(self, offset, entries)
height = height, height = height,
zindex = 1001, zindex = 1001,
}) })
self.entries_win:option('cursorline', false)
vim.api.nvim_win_set_cursor(self.entries_win.win, { 1, 1 }) vim.api.nvim_win_set_cursor(self.entries_win.win, { 1, 1 })
if preselect > 0 and config.get().preselect == types.cmp.PreselectMode.Item then if preselect > 0 and config.get().preselect == types.cmp.PreselectMode.Item then

View File

@@ -33,7 +33,7 @@ native_entries_view.ready = function(_)
return vim.fn.complete_info({ 'mode' }).mode == 'eval' return vim.fn.complete_info({ 'mode' }).mode == 'eval'
end end
native_entries_view.redraw = function(self) native_entries_view.on_change = function(self)
if #self.entries > 0 and self.offset <= vim.api.nvim_win_get_cursor(0)[2] + 1 then if #self.entries > 0 and self.offset <= vim.api.nvim_win_get_cursor(0)[2] + 1 then
local completeopt = vim.o.completeopt local completeopt = vim.o.completeopt
vim.o.completeopt = self.preselect_index == 1 and 'menu,menuone,noinsert' or config.get().completion.completeopt vim.o.completeopt = self.preselect_index == 1 and 'menu,menuone,noinsert' or config.get().completion.completeopt