mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-14 01:50:27 +00:00
feat: highlight current file
This commit is contained in:
parent
19309b636f
commit
09c6d045fb
@ -258,6 +258,14 @@ harpoon:extend({
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Builtin Extensions
|
||||||
|
Highlight current file in the harpoon buffer list
|
||||||
|
|
||||||
|
```lua
|
||||||
|
local harpoon_extensions = require("harpoon.extensions")
|
||||||
|
harpoon:extend(harpoon_extensions.highlight_current_file())
|
||||||
|
```
|
||||||
|
|
||||||
### Highlight Groups
|
### Highlight Groups
|
||||||
TODO: Fill in the idea that we will emit out window information
|
TODO: Fill in the idea that we will emit out window information
|
||||||
|
|
||||||
|
@ -99,27 +99,4 @@ function M.set_contents(bufnr, contents)
|
|||||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, contents)
|
vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, contents)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.set_current_menu_item_highlight(
|
|
||||||
bufnr,
|
|
||||||
win_id,
|
|
||||||
current_file,
|
|
||||||
contents
|
|
||||||
)
|
|
||||||
for line_number, file in pairs(contents) do
|
|
||||||
if string.find(current_file, file, 1, true) 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
|
return M
|
||||||
|
@ -64,6 +64,28 @@ function Builtins.navigate_with_number()
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Builtins.highlight_current_file()
|
||||||
|
return {
|
||||||
|
UI_CREATE = function(cx)
|
||||||
|
for line_number, file in pairs(cx.contents) do
|
||||||
|
if string.find(cx.current_file, file, 1, true) then
|
||||||
|
-- highlight the harpoon menu line that corresponds to the current buffer
|
||||||
|
vim.api.nvim_buf_add_highlight(
|
||||||
|
cx.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(cx.win_id, { line_number, 0 })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
builtins = Builtins,
|
builtins = Builtins,
|
||||||
extensions = extensions,
|
extensions = extensions,
|
||||||
|
@ -154,17 +154,12 @@ function HarpoonUI:toggle_quick_menu(list, opts)
|
|||||||
local contents = self.active_list:display()
|
local contents = self.active_list:display()
|
||||||
|
|
||||||
vim.api.nvim_buf_set_lines(self.bufnr, 0, -1, false, contents)
|
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, {
|
Extensions.extensions:emit(Extensions.event_names.UI_CREATE, {
|
||||||
win_id = win_id,
|
win_id = win_id,
|
||||||
bufnr = bufnr,
|
bufnr = bufnr,
|
||||||
current_file = current_file,
|
current_file = current_file,
|
||||||
|
contents = contents,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user