mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-13 17:40:25 +00:00
Highlight the current buffer in the harpoon menu and match the cursor
position if it exists
This commit is contained in:
parent
3b8cf0e1ea
commit
27fce89fe8
@ -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
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user