From 1e913aefd9c853238ff54ff276e832e9bca7ee9c Mon Sep 17 00:00:00 2001 From: hrsh7th Date: Mon, 18 Oct 2021 11:47:17 +0900 Subject: [PATCH] Fix #345 --- lua/cmp/utils/window.lua | 4 ++-- lua/cmp/view/custom_entries_view.lua | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lua/cmp/utils/window.lua b/lua/cmp/utils/window.lua index f6b3afa..4d1a6aa 100644 --- a/lua/cmp/utils/window.lua +++ b/lua/cmp/utils/window.lua @@ -120,7 +120,7 @@ window.update = function(self) else style1.noautocmd = true self.swin1 = vim.api.nvim_open_win(buffer.ensure(self.name .. 'sbuf1'), false, style1) - vim.api.nvim_win_set_option(self.swin1, 'winhighlight', 'Normal:PmenuSbar,NormalNC:PmenuSbar,NormalFloat:PmenuSbar') + vim.api.nvim_win_set_option(self.swin1, 'winhighlight', 'EndOfBuffer:PmenuSbar,Normal:PmenuSbar,NormalNC:PmenuSbar,NormalFloat:PmenuSbar') end local style2 = {} style2.relative = 'editor' @@ -135,7 +135,7 @@ window.update = function(self) else style2.noautocmd = true self.swin2 = vim.api.nvim_open_win(buffer.ensure(self.name .. 'sbuf2'), false, style2) - vim.api.nvim_win_set_option(self.swin2, 'winhighlight', 'Normal:PmenuThumb,NormalNC:PmenuThumb,NormalFloat:PmenuThumb') + vim.api.nvim_win_set_option(self.swin2, 'winhighlight', 'EndOfBuffer:PmenuThumb,Normal:PmenuThumb,NormalNC:PmenuThumb,NormalFloat:PmenuThumb') end else if self.swin1 and vim.api.nvim_win_is_valid(self.swin1) then diff --git a/lua/cmp/view/custom_entries_view.lua b/lua/cmp/view/custom_entries_view.lua index 500450d..49210a6 100644 --- a/lua/cmp/view/custom_entries_view.lua +++ b/lua/cmp/view/custom_entries_view.lua @@ -129,7 +129,6 @@ custom_entries_view.open = function(self, offset, entries) width = width + self.column_width.kind + (self.column_width.menu > 0 and 1 or 0) width = width + self.column_width.menu + 1 - local cursor = api.get_cursor() local pos = api.get_screen_cursor() local height = vim.api.nvim_get_option('pumheight') height = height == 0 and #self.entries or height @@ -145,18 +144,24 @@ custom_entries_view.open = function(self, offset, entries) return end + local cursor = api.get_cursor() local delta = cursor[2] + 1 - self.offset + local row, col = pos[1], pos[2] - delta - 1 + if row < 0 or vim.o.lines <= row or col < 0 or vim.o.columns <= col then + return + end + self.entries_win:open({ relative = 'editor', style = 'minimal', - row = pos[1], - col = pos[2] - delta - 1, + row = row, + col = col, width = width, height = height, zindex = 1001, }) - self.entries_win:option('cursorline', false) vim.api.nvim_win_set_cursor(self.entries_win.win, { 1, 1 }) + self.entries_win:option('cursorline', false) if preselect > 0 and config.get().preselect == types.cmp.PreselectMode.Item then self:preselect(preselect)