From be7bd4c5f860c79da97af3a26d489af50babfd4b Mon Sep 17 00:00:00 2001 From: Epheien Date: Thu, 21 Nov 2024 16:51:29 +0800 Subject: [PATCH] fix: scrollbar thumb ui issue (#2068) Co-authored-by: eph --- lua/cmp/utils/window.lua | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lua/cmp/utils/window.lua b/lua/cmp/utils/window.lua index 1f3ddac..1384150 100644 --- a/lua/cmp/utils/window.lua +++ b/lua/cmp/utils/window.lua @@ -156,14 +156,23 @@ window.update = function(self) end -- Draw the scrollbar thumb - local thumb_height = math.floor(info.inner_height * (info.inner_height / self:get_content_height()) + 0.5) - local thumb_offset = math.floor(info.inner_height * (vim.fn.getwininfo(self.win)[1].topline / self:get_content_height())) + local thumb_height = math.floor(info.inner_height * (info.inner_height / self:get_content_height())) + thumb_height = math.max(1, thumb_height) + local topline = vim.fn.getwininfo(self.win)[1].topline + local scroll_ratio = topline / (self:get_content_height() - info.inner_height + 1) + -- row grid start from 0 on nvim-0.10 + local thumb_offset_raw = (info.inner_height - thumb_height) * scroll_ratio + -- round half if topline > 1 + local thumb_offset = math.floor(thumb_offset_raw) + if topline > 1 and thumb_offset_raw + 0.5 >= thumb_offset + 1 then + thumb_offset = thumb_offset + 1 + end local style = { relative = 'editor', style = 'minimal', width = 1, - height = math.max(1, thumb_height), + height = thumb_height, row = info.row + thumb_offset + (info.border_info.visible and info.border_info.top or 0), col = info.col + info.width - 1, -- info.col was already added scrollbar offset. zindex = (self.style.zindex and (self.style.zindex + 2) or 2),