Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: scrollbar thumb ui issue #2068

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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