diff --git a/README.md b/README.md index 2196575e..e82aa998 100644 --- a/README.md +++ b/README.md @@ -443,6 +443,13 @@ https://github.com/Bekaboo/dropbar.nvim/assets/76579810/e8c1ac26-0321-4762-9975- right = 1, }, }, + -- Menu scrollbar options + scrollbar = { + enable = true, + -- The background / gutter of the scrollbar + -- When false, only the scrollbar thumb is shown. + background = true + }, ---@type table> keymaps = { [''] = function() @@ -515,8 +522,13 @@ https://github.com/Bekaboo/dropbar.nvim/assets/76579810/e8c1ac26-0321-4762-9975- ---@param menu dropbar_menu_t col = function(menu) if menu.prev_menu then - return menu.prev_menu._win_configs.width - + (menu.prev_menu.scrollbar and 1 or 0) + local offset = 0 + if + menu.prev_menu.scrollbar and M.opts.menu.scrollbar.background + then + offset = 1 + end + return menu.prev_menu._win_configs.width + offset end local mouse = vim.fn.getmousepos() local bar = utils.bar.get({ win = menu.prev_win }) @@ -1123,6 +1135,18 @@ menu: end }, ``` + +- `opts.menu.scrollbar`: `table` + - Scrollbar configuration for the menu. + - Default: + ```lua + { + enable = true, + -- if false, only the scrollbar thumb will be shown + background = true + } + ``` + - `opts.menu.win_configs`: `table` - Window configurations for the menu, see `:h nvim_open_win()` - Each config key in `opts.menu.win_configs` accepts either a plain value diff --git a/doc/dropbar.txt b/doc/dropbar.txt index 1ab9ebb7..d0ce71a4 100644 --- a/doc/dropbar.txt +++ b/doc/dropbar.txt @@ -541,6 +541,16 @@ the menu: end }, < +- `opts.menu.scrollbar`: `table` + - Scrollbar configuration for the menu. + - Default: >lua + { + enable = true, + -- if false, only the scrollbar thumb will be shown + background = true + } +< + - `opts.menu.win_configs`: `table` - Window configurations for the menu, see `:h nvim_open_win()` - Each config key in `opts.menu.win_configs` accepts either a plain value diff --git a/lua/dropbar/configs.lua b/lua/dropbar/configs.lua index 06dae5ad..b32783e8 100644 --- a/lua/dropbar/configs.lua +++ b/lua/dropbar/configs.lua @@ -209,6 +209,13 @@ M.opts = { right = 1, }, }, + -- Menu scrollbar options + scrollbar = { + enable = true, + -- The background / gutter of the scrollbar + -- When false, only the thumb is shown. + background = true, + }, ---@type table> keymaps = { [''] = function() @@ -281,8 +288,11 @@ M.opts = { ---@param menu dropbar_menu_t col = function(menu) if menu.prev_menu then - return menu.prev_menu._win_configs.width - + (menu.prev_menu.scrollbar and 1 or 0) + local offset = 0 + if menu.prev_menu.scrollbar and M.opts.menu.scrollbar.background then + offset = 1 + end + return menu.prev_menu._win_configs.width + offset end local mouse = vim.fn.getmousepos() local bar = utils.bar.get({ win = menu.prev_win }) diff --git a/lua/dropbar/menu.lua b/lua/dropbar/menu.lua index 44c9ef83..defeb73e 100644 --- a/lua/dropbar/menu.lua +++ b/lua/dropbar/menu.lua @@ -189,7 +189,7 @@ end ---@field prev_cursor integer[]? previous cursor position ---@field symbol_previewed dropbar_symbol_t? symbol being previewed ---@field fzf_state fzf_state_t? fuzzy-finding state, or nil if not currently fuzzy-finding ----@field scrollbar { thumb: integer, sbar: integer }? scrollbar window handlers +---@field scrollbar { thumb: integer, background: integer }? scrollbar window handlers local dropbar_menu_t = {} dropbar_menu_t.__index = dropbar_menu_t @@ -538,6 +538,7 @@ function dropbar_menu_t:update_scrollbar() or not self.buf or not vim.api.nvim_win_is_valid(self.win) or not vim.api.nvim_buf_is_valid(self.buf) + or not configs.opts.menu.scrollbar.enable then return end @@ -568,26 +569,31 @@ function dropbar_menu_t:update_scrollbar() self.scrollbar = {} local win_configs = { - row = 0, - col = menu_win_configs.width, + row = offset, + col = menu_win_configs.width + - (configs.opts.menu.scrollbar.background and 0 or 1), width = 1, height = menu_win_configs.height, style = 'minimal', border = 'none', relative = 'win', win = self.win, - zindex = menu_win_configs.zindex, + zindex = menu_win_configs.zindex + + (configs.opts.menu.scrollbar.background and 0 or 1), } - self.scrollbar.sbar = vim.api.nvim_open_win( - vim.api.nvim_create_buf(false, true), - false, - win_configs - ) - vim.wo[self.scrollbar.sbar].winhl = 'NormalFloat:DropBarMenuSbar' - win_configs.row = offset - win_configs.height = thumb_height - win_configs.zindex = menu_win_configs.zindex + 1 + if configs.opts.menu.scrollbar.background then + win_configs.row = 0 + win_configs.height = menu_win_configs.height + win_configs.zindex = win_configs.zindex - 1 + self.scrollbar.background = vim.api.nvim_open_win( + vim.api.nvim_create_buf(false, true), + false, + win_configs + ) + vim.wo[self.scrollbar.background].winhl = 'NormalFloat:DropBarMenuSbar' + end + self.scrollbar.thumb = vim.api.nvim_open_win( vim.api.nvim_create_buf(false, true), false, @@ -607,8 +613,11 @@ function dropbar_menu_t:close_scrollbar() if vim.api.nvim_win_is_valid(self.scrollbar.thumb) then vim.api.nvim_win_close(self.scrollbar.thumb, true) end - if vim.api.nvim_win_is_valid(self.scrollbar.sbar) then - vim.api.nvim_win_close(self.scrollbar.sbar, true) + if + self.scrollbar.background + and vim.api.nvim_win_is_valid(self.scrollbar.background) + then + vim.api.nvim_win_close(self.scrollbar.background, true) end self.scrollbar = nil end