summaryrefslogtreecommitdiff
path: root/lua/blink/cmp/lib/window/scrollbar/init.lua
diff options
context:
space:
mode:
authorMike Vink <mike@pionative.com>2025-01-19 13:52:52 +0100
committerMike Vink <mike@pionative.com>2025-01-19 13:52:52 +0100
commitb77413ff8f59f380612074f0c9bd49093d8db695 (patch)
tree32c39a811ba96ed4ab0a1c81cce9f8d518ed7e31 /lua/blink/cmp/lib/window/scrollbar/init.lua
Squashed 'mut/neovim/pack/plugins/start/blink.cmp/' content from commit 1cc3b1a
git-subtree-dir: mut/neovim/pack/plugins/start/blink.cmp git-subtree-split: 1cc3b1a908fbcfd15451c4772759549724f38524
Diffstat (limited to 'lua/blink/cmp/lib/window/scrollbar/init.lua')
-rw-r--r--lua/blink/cmp/lib/window/scrollbar/init.lua37
1 files changed, 37 insertions, 0 deletions
diff --git a/lua/blink/cmp/lib/window/scrollbar/init.lua b/lua/blink/cmp/lib/window/scrollbar/init.lua
new file mode 100644
index 0000000..c72615a
--- /dev/null
+++ b/lua/blink/cmp/lib/window/scrollbar/init.lua
@@ -0,0 +1,37 @@
+-- TODO: move the set_config and set_height calls from the menu/documentation/signature files
+-- to helpers in the window lib, and call scrollbar updates from there. This way, consumers of
+-- the window lib don't need to worry about scrollbars
+
+--- @class blink.cmp.ScrollbarConfig
+--- @field enable_gutter boolean
+
+--- @class blink.cmp.Scrollbar
+--- @field win blink.cmp.ScrollbarWin
+---
+--- @field new fun(opts: blink.cmp.ScrollbarConfig): blink.cmp.Scrollbar
+--- @field is_visible fun(self: blink.cmp.Scrollbar): boolean
+--- @field update fun(self: blink.cmp.Scrollbar, target_win: number | nil)
+
+--- @type blink.cmp.Scrollbar
+--- @diagnostic disable-next-line: missing-fields
+local scrollbar = {}
+
+function scrollbar.new(opts)
+ local self = setmetatable({}, { __index = scrollbar })
+ self.win = require('blink.cmp.lib.window.scrollbar.win').new(opts)
+ return self
+end
+
+function scrollbar:is_visible() return self.win:is_visible() end
+
+function scrollbar:update(target_win)
+ if target_win == nil or not vim.api.nvim_win_is_valid(target_win) then return self.win:hide() end
+
+ local geometry = require('blink.cmp.lib.window.scrollbar.geometry').get_geometry(target_win)
+ if geometry.should_hide then return self.win:hide() end
+
+ self.win:show_thumb(geometry.thumb)
+ self.win:show_gutter(geometry.gutter)
+end
+
+return scrollbar