Skip to content

Commit

Permalink
fix: scrollbar thumb ui issue (#2068)
Browse files Browse the repository at this point in the history
Co-authored-by: eph <eph@MacBook-Pro.local>
  • Loading branch information
epheien and eph authored Nov 21, 2024
1 parent 2d7e6da commit be7bd4c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lua/cmp/utils/window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit be7bd4c

Please sign in to comment.