diff --git a/lua/harpoon/buffer.lua b/lua/harpoon/buffer.lua index a6a9fd3..b351f62 100644 --- a/lua/harpoon/buffer.lua +++ b/lua/harpoon/buffer.lua @@ -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 diff --git a/lua/harpoon/ui.lua b/lua/harpoon/ui.lua index eb76c17..2e524e5 100644 --- a/lua/harpoon/ui.lua +++ b/lua/harpoon/ui.lua @@ -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,