From 3fe7acf2b20ced66d5a27577e0965089d2cc7fa2 Mon Sep 17 00:00:00 2001 From: Will Hopkins Date: Mon, 25 Sep 2023 06:03:32 -0700 Subject: [PATCH 1/3] feat(menu): allow showing virtual text below entries --- lua/dropbar/menu.lua | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lua/dropbar/menu.lua b/lua/dropbar/menu.lua index 6e27a032..25866e07 100644 --- a/lua/dropbar/menu.lua +++ b/lua/dropbar/menu.lua @@ -17,6 +17,7 @@ _G.dropbar.menus = {} ---@field separator dropbar_symbol_t ---@field padding {left: integer, right: integer} ---@field components dropbar_symbol_t[] +---@field virt_text string[][]? ---@field menu dropbar_menu_t? the menu the entry belongs to ---@field idx integer? the index of the entry in the menu local dropbar_menu_entry_t = {} @@ -26,6 +27,7 @@ dropbar_menu_entry_t.__index = dropbar_menu_entry_t ---@field separator dropbar_symbol_t? ---@field padding {left: integer, right: integer}? ---@field components dropbar_symbol_t[]? +---@field virt_text string[][]? ---@field menu dropbar_menu_t? the menu the entry belongs to ---@field idx integer? the index of the entry in the menu @@ -398,8 +400,9 @@ end ---highlights to the buffer function dropbar_menu_t:fill_buf() local lines = {} ---@type string[] + local extmarks = {} ---@type table local hl_info = {} ---@type dropbar_menu_hl_info_t[][] - for _, entry in ipairs(self.entries) do + for i, entry in ipairs(self.entries) do local line, entry_hl_info = entry:cat() -- Pad lines with spaces to the width of the window -- This is to make sure hl-DropBarMenuCurrentContext colors @@ -413,9 +416,29 @@ function dropbar_menu_t:fill_buf() ) ) table.insert(hl_info, entry_hl_info) + if entry.virt_text then + table.insert(extmarks, i, entry.virt_text) + end end vim.api.nvim_buf_set_lines(self.buf, 0, -1, false, lines) self:add_hl(hl_info) + + local extmark_ns = vim.api.nvim_create_namespace('dropbar_extmarks') + vim.api.nvim_buf_clear_namespace(self.buf, extmark_ns, 0, -1) + + for i, virt_text in pairs(extmarks) do + if type(i) == 'number' then + vim.api.nvim_buf_set_extmark( + self.buf, + extmark_ns, + i - 1, -- 0-indexed + 0, + { + virt_lines = { virt_text }, + } + ) + end + end end ---Make a buffer for the menu and set buffer-local keymaps From 74aa5cd08e759771f145aca16367d04c80fc125f Mon Sep 17 00:00:00 2001 From: Will Hopkins Date: Mon, 25 Sep 2023 23:28:16 -0700 Subject: [PATCH 2/3] docs: document virt text property --- README.md | 1 + doc/dropbar.txt | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 682b8d80..b2117847 100644 --- a/README.md +++ b/README.md @@ -1973,6 +1973,7 @@ multiple `dropbar_menu_entry_t` instances while a | `separator` | [`dropbar_symbol_t`](#dropbar_symbol_t) | separator to use in the entry | | `padding` | `{left: integer, right: integer}` | padding to use between the menu entry and the menu border | | `components` | [`dropbar_symbol_t[]`](#dropbar_symbol_t) | components[`dropbar_symbol_t[]`](#dropbar_symbol_t) in the entry | +| `virt_text` | `string[][]?` | list of virtual text chunks to display below the entry | | `menu` | [`dropbar_menu_t?`](#dropbar_menu_t) | the menu the entry belongs to | | `idx` | `integer?` | the index of the entry in the menu | diff --git a/doc/dropbar.txt b/doc/dropbar.txt index 7b42fe32..f9dcd27e 100644 --- a/doc/dropbar.txt +++ b/doc/dropbar.txt @@ -1832,21 +1832,21 @@ contain multiple `dropbar_symbol_t` instances. `dropbar_menu_entry_t` has the following fields: -dropbar_menu_t.separator *dropbar_menu_t.separator* +dropbar_menu_entry_t.separator *dropbar_menu_t.separator* Separator to use in the entry Type ~ `dropbar_symbol_t` -dropbar_menu_t.padding *dropbar_menu_t.padding* +dropbar_menu_entry_t.padding *dropbar_menu_t.padding* Padding to use between the menu entry and the menu border Type ~ { left: integer, right: integer } -dropbar_menu_t.components *dropbar_menu_t.components* +dropbar_menu_entry_t.components *dropbar_menu_t.components* Symbols got from sources |dropbar-developers-classes-dropbar_source_t| in the entry @@ -1854,14 +1854,22 @@ dropbar_menu_t.components *dropbar_menu_t.components* Type ~ `dropbar_symbol_t`[] -dropbar_menu_t.menu *dropbar_menu_t.menu* +dropbar_menu_entry_t.virt_text *dropbar_menu_t.virt_text* + + Symbols got from sources |dropbar-developers-classes-dropbar_source_t| + in the entry + + Type ~ + `string`[][]? + +dropbar_menu_entry_t.menu *dropbar_menu_t.menu* The menu the entry belongs to Type ~ `dropbar_menu_t`? -dropbar_menu_t.idx *dropbar_menu_t.idx* +dropbar_menu_entry_t.idx *dropbar_menu_t.idx* The index of the entry in the menu From 02f7a5e788924efcb65ccdf9b4737d442c4284f9 Mon Sep 17 00:00:00 2001 From: Will Hopkins Date: Tue, 26 Sep 2023 21:21:44 -0700 Subject: [PATCH 3/3] refactor(extmarks): use PascalCase for namespace id --- lua/dropbar/menu.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/dropbar/menu.lua b/lua/dropbar/menu.lua index 25866e07..4da1b0d2 100644 --- a/lua/dropbar/menu.lua +++ b/lua/dropbar/menu.lua @@ -423,7 +423,7 @@ function dropbar_menu_t:fill_buf() vim.api.nvim_buf_set_lines(self.buf, 0, -1, false, lines) self:add_hl(hl_info) - local extmark_ns = vim.api.nvim_create_namespace('dropbar_extmarks') + local extmark_ns = vim.api.nvim_create_namespace('DropBarExtmarks') vim.api.nvim_buf_clear_namespace(self.buf, extmark_ns, 0, -1) for i, virt_text in pairs(extmarks) do