Skip to content

Commit

Permalink
feat: allow individual hl custamization of scrollbar for docs and menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Elize authored and Jonathan Elize committed Nov 2, 2024
1 parent f17d9b4 commit edf22a8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
12 changes: 12 additions & 0 deletions doc/cmp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,18 @@ window.{completion,documentation}.border~
window.{completion,documentation}.winhighlight~
`string | cmp.WinhighlightConfig`
Specify the window's winhighlight option.
See |nvim_open_win|.

*cmp-config.window.{completion,documentation}.scrollbar_winhighlight*
window.{completion,documentation}.scrollbar_winhighlight~
`string | nil`
Specify the winhighlight option for the scrollbar background.
See |nvim_open_win|.

*cmp-config.window.{completion,documentation}.scrollbar_thumb_winhighlight*
window.{completion,documentation}.scrollbar_thumb_winhighlight~
`string | nil`
Specify the winhighlight option for the scrollbar thumb.
See |nvim_open_win|.

*cmp-config.window.{completion,documentation}.winblend*
Expand Down
4 changes: 4 additions & 0 deletions lua/cmp/config/default.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ return function()
completion = {
border = { '', '', '', '', '', '', '', '' },
winhighlight = 'Normal:Pmenu,FloatBorder:Pmenu,CursorLine:PmenuSel,Search:None',
scrollbar_winhighlight = 'EndOfBuffer:PmenuSbar,NormalFloat:PmenuSbar',
scrollbar_thumb_winhighlight = 'EndOfBuffer:PmenuThumb,NormalFloat:PmenuThumb',
winblend = vim.o.pumblend,
scrolloff = 0,
col_offset = 0,
Expand All @@ -120,6 +122,8 @@ return function()
max_width = math.floor((WIDE_HEIGHT * 2) * (vim.o.columns / (WIDE_HEIGHT * 2 * 16 / 9))),
border = { '', '', '', ' ', '', '', '', ' ' },
winhighlight = 'FloatBorder:NormalFloat',
scrollbar_winhighlight = 'EndOfBuffer:PmenuSbar,NormalFloat:PmenuSbar',
scrollbar_thumb_winhighlight = 'EndOfBuffer:PmenuThumb,NormalFloat:PmenuThumb',
winblend = vim.o.pumblend,
},
},
Expand Down
2 changes: 2 additions & 0 deletions lua/cmp/types/cmp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ cmp.ItemField = {
---@class cmp.WindowOptions
---@field public border? string|string[]
---@field public winhighlight? string
---@field public scrollbar_winhighlight? string
---@field public scrollbar_thumb_winhighlight? string
---@field public winblend? number
---@field public zindex? integer|nil

Expand Down
7 changes: 5 additions & 2 deletions lua/cmp/utils/window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ local config = require('cmp.config')
---@field public thumb_win integer|nil
---@field public sbar_win integer|nil
---@field public style cmp.WindowStyle
---@field public is_doc boolean|nil
---@field public opt table<string, any>
---@field public buffer_opt table<string, any>
local window = {}
Expand Down Expand Up @@ -134,6 +135,8 @@ end
window.update = function(self)
local info = self:info()
if info.scrollable and self.style.height > 0 then
local scrollbar_winhighlight = self.is_doc and config.get().window.completion.scrollbar_winhighlight or config.get().window.documentation.scrollbar_winhighlight
local scrollbar_thumb_winhighlight = self.is_doc and config.get().window.completion.scrollbar_thumb_winhighlight or config.get().window.documentation.scrollbar_thumb_winhighlight
-- Draw the background of the scrollbar

if not info.border_info.visible then
Expand All @@ -151,7 +154,7 @@ window.update = function(self)
else
style.noautocmd = true
self.sbar_win = vim.api.nvim_open_win(buffer.ensure(self.name .. 'sbar_buf'), false, style)
opt.win_set_option(self.sbar_win, 'winhighlight', 'EndOfBuffer:PmenuSbar,NormalFloat:PmenuSbar')
opt.win_set_option(self.sbar_win, 'winhighlight', scrollbar_winhighlight)
end
end

Expand All @@ -173,7 +176,7 @@ window.update = function(self)
else
style.noautocmd = true
self.thumb_win = vim.api.nvim_open_win(buffer.ensure(self.name .. 'thumb_buf'), false, style)
opt.win_set_option(self.thumb_win, 'winhighlight', 'EndOfBuffer:PmenuThumb,NormalFloat:PmenuThumb')
opt.win_set_option(self.thumb_win, 'winhighlight', scrollbar_thumb_winhighlight)
end
else
if self.sbar_win and vim.api.nvim_win_is_valid(self.sbar_win) then
Expand Down
1 change: 1 addition & 0 deletions lua/cmp/view/docs_view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ docs_view.new = function()
self.window:option('wrap', true)
self.window:buffer_option('filetype', 'cmp_docs')
self.window:buffer_option('buftype', 'nofile')
self.window.is_doc = true
return self
end

Expand Down

0 comments on commit edf22a8

Please sign in to comment.