From a2727839d3648b729a1bf7b9964b44cc03c67e8e Mon Sep 17 00:00:00 2001 From: bekaboo Date: Wed, 15 Jan 2025 21:19:21 -0500 Subject: [PATCH] refactor(menu): pad last symbol in winbar menu So that the cursor will always on at least one symbol when inside a winbar menu. --- lua/dropbar/menu.lua | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lua/dropbar/menu.lua b/lua/dropbar/menu.lua index 1662975e..0144dce2 100644 --- a/lua/dropbar/menu.lua +++ b/lua/dropbar/menu.lua @@ -394,14 +394,16 @@ function dropbar_menu_t:fill_buf() -- Pad lines with spaces to the width of the window -- This is to make sure hl-DropBarMenuCurrentContext colors -- the entire line - table.insert( - lines, - line - .. string.rep( - ' ', - self._win_configs.width - vim.fn.strdisplaywidth(line) - ) - ) + -- Also pad the last symbol's name so that cursor is always + -- on at least one symbol when inside the menu + local width_diff = self._win_configs.width - entry:displaywidth() + if width_diff > 0 then + local width_pad = string.rep(' ', width_diff) + local last_sym = entry.components[#entry.components] + last_sym.name = last_sym.name .. width_pad + line = line .. width_pad + end + table.insert(lines, line) table.insert(hl_info, entry_hl_info) if entry.virt_text then table.insert(extmarks, i, entry.virt_text)