Highlight the current buffer in the harpoon menu and match the cursor

position if it exists
This commit is contained in:
Elvis Hernandez 2025-01-09 15:48:16 -05:00 committed by Prime Again
parent 3b8cf0e1ea
commit 27fce89fe8
2 changed files with 30 additions and 0 deletions

View File

@ -99,4 +99,27 @@ function M.set_contents(bufnr, contents)
vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, contents)
end
function M.set_current_menu_item_highlight(
bufnr,
win_id,
current_file,
contents
)
for line_number, file in pairs(contents) do
if string.match(current_file, file) then
-- highlight the harpoon menu line that corresponds to the current buffer
vim.api.nvim_buf_add_highlight(
bufnr,
-1,
"CursorLineNr",
line_number - 1,
0,
-1
)
-- set the position of the cursor in the harpoon menu to the start of the current buffer line
vim.api.nvim_win_set_cursor(win_id, { line_number, 0 })
end
end
end
return M

View File

@ -152,7 +152,14 @@ function HarpoonUI:toggle_quick_menu(list, opts)
self.active_list = list
local contents = self.active_list:display()
vim.api.nvim_buf_set_lines(self.bufnr, 0, -1, false, contents)
Buffer.set_current_menu_item_highlight(
bufnr,
win_id,
current_file,
contents
)
Extensions.extensions:emit(Extensions.event_names.UI_CREATE, {
win_id = win_id,