From f0a6cca5b9c6d9c1fb960ec4eed557eb12121e34 Mon Sep 17 00:00:00 2001 From: hrsh7th Date: Sat, 16 Oct 2021 22:09:01 +0900 Subject: [PATCH] Fix #355 --- lua/cmp/core.lua | 6 ++++-- lua/cmp/view.lua | 6 +++--- lua/cmp/view/custom_entries_view.lua | 9 ++++++--- lua/cmp/view/native_entries_view.lua | 2 +- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lua/cmp/core.lua b/lua/cmp/core.lua index 6003c9e..d9d673d 100644 --- a/lua/cmp/core.lua +++ b/lua/cmp/core.lua @@ -162,10 +162,9 @@ core.on_change = function(self, event) self:autoindent(event, function() local ctx = self:get_context({ reason = types.cmp.ContextReason.Auto }) - debug.log(('ctx: `%s`'):format(ctx.cursor_before_line)) if ctx:changed(ctx.prev_context) then - self.view:redraw() + self.view:on_change() debug.log('changed') 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 return end + if self.view:get_active_entry() ~= nil then + return + end local ctx = self:get_context() -- To wait for processing source for that's timeout. diff --git a/lua/cmp/view.lua b/lua/cmp/view.lua index c3debdf..2e4b662 100644 --- a/lua/cmp/view.lua +++ b/lua/cmp/view.lua @@ -36,9 +36,9 @@ view.ready = function(self) return self:_get_entries_view():ready() end ----Redraw menu. -view.redraw = function(self) - self:_get_entries_view():redraw() +---OnChange handler. +view.on_change = function(self) + self:_get_entries_view():on_change() end ---Open menu diff --git a/lua/cmp/view/custom_entries_view.lua b/lua/cmp/view/custom_entries_view.lua index d265c9f..8b8cc5f 100644 --- a/lua/cmp/view/custom_entries_view.lua +++ b/lua/cmp/view/custom_entries_view.lua @@ -87,8 +87,11 @@ custom_entries_view.ready = function() return vim.fn.pumvisible() == 0 end -custom_entries_view.redraw = function() - -- noop +custom_entries_view.on_change = function(self) + 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 custom_entries_view.open = function(self, offset, entries) @@ -143,7 +146,6 @@ custom_entries_view.open = function(self, offset, entries) end local delta = cursor[2] + 1 - self.offset - self.entries_win:option('cursorline', false) self.entries_win:open({ relative = 'editor', style = 'minimal', @@ -153,6 +155,7 @@ custom_entries_view.open = function(self, offset, entries) height = height, zindex = 1001, }) + self.entries_win:option('cursorline', false) vim.api.nvim_win_set_cursor(self.entries_win.win, { 1, 1 }) if preselect > 0 and config.get().preselect == types.cmp.PreselectMode.Item then diff --git a/lua/cmp/view/native_entries_view.lua b/lua/cmp/view/native_entries_view.lua index caa11d1..0b810c9 100644 --- a/lua/cmp/view/native_entries_view.lua +++ b/lua/cmp/view/native_entries_view.lua @@ -33,7 +33,7 @@ native_entries_view.ready = function(_) return vim.fn.complete_info({ 'mode' }).mode == 'eval' 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 local completeopt = vim.o.completeopt vim.o.completeopt = self.preselect_index == 1 and 'menu,menuone,noinsert' or config.get().completion.completeopt