Skip to content

Commit be7bd4c

Browse files
epheieneph
andauthored
fix: scrollbar thumb ui issue (#2068)
Co-authored-by: eph <[email protected]>
1 parent 2d7e6da commit be7bd4c

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lua/cmp/utils/window.lua

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,23 @@ window.update = function(self)
156156
end
157157

158158
-- Draw the scrollbar thumb
159-
local thumb_height = math.floor(info.inner_height * (info.inner_height / self:get_content_height()) + 0.5)
160-
local thumb_offset = math.floor(info.inner_height * (vim.fn.getwininfo(self.win)[1].topline / self:get_content_height()))
159+
local thumb_height = math.floor(info.inner_height * (info.inner_height / self:get_content_height()))
160+
thumb_height = math.max(1, thumb_height)
161+
local topline = vim.fn.getwininfo(self.win)[1].topline
162+
local scroll_ratio = topline / (self:get_content_height() - info.inner_height + 1)
163+
-- row grid start from 0 on nvim-0.10
164+
local thumb_offset_raw = (info.inner_height - thumb_height) * scroll_ratio
165+
-- round half if topline > 1
166+
local thumb_offset = math.floor(thumb_offset_raw)
167+
if topline > 1 and thumb_offset_raw + 0.5 >= thumb_offset + 1 then
168+
thumb_offset = thumb_offset + 1
169+
end
161170

162171
local style = {
163172
relative = 'editor',
164173
style = 'minimal',
165174
width = 1,
166-
height = math.max(1, thumb_height),
175+
height = thumb_height,
167176
row = info.row + thumb_offset + (info.border_info.visible and info.border_info.top or 0),
168177
col = info.col + info.width - 1, -- info.col was already added scrollbar offset.
169178
zindex = (self.style.zindex and (self.style.zindex + 2) or 2),

0 commit comments

Comments
 (0)