fix: scrollbar thumb ui issue (#2068)

Co-authored-by: eph <eph@MacBook-Pro.local>
This commit is contained in:
Epheien
2024-11-21 16:51:29 +08:00
committed by GitHub
parent 2d7e6da1ec
commit be7bd4c5f8

View File

@@ -156,14 +156,23 @@ window.update = function(self)
end end
-- Draw the scrollbar thumb -- Draw the scrollbar thumb
local thumb_height = math.floor(info.inner_height * (info.inner_height / self:get_content_height()) + 0.5) local thumb_height = math.floor(info.inner_height * (info.inner_height / self:get_content_height()))
local thumb_offset = math.floor(info.inner_height * (vim.fn.getwininfo(self.win)[1].topline / 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 = { local style = {
relative = 'editor', relative = 'editor',
style = 'minimal', style = 'minimal',
width = 1, 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), 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. col = info.col + info.width - 1, -- info.col was already added scrollbar offset.
zindex = (self.style.zindex and (self.style.zindex + 2) or 2), zindex = (self.style.zindex and (self.style.zindex + 2) or 2),