feat: Jump highlight customizations

Closes #27

- Highlight group 'OutlineJumpHighlight' (links to Visual by default)
- Config: outline_window.jump_highlight_duration (integer for
  milliseconds, or boolean to enable/disable)
This commit is contained in:
hedy
2023-11-16 22:14:47 +08:00
parent fdc7c6391f
commit 134b7e2f39
4 changed files with 30 additions and 3 deletions

View File

@@ -32,6 +32,7 @@ M.defaults = {
show_cursorline = true,
hide_cursor = false,
winhl = "OutlineDetails:Comment,OutlineLineno:LineNr",
jump_highlight_duration = 500,
},
preview_window = {
auto_preview = false,

View File

@@ -105,7 +105,17 @@ function M.__goto_location(change_focus)
M.state.code_win,
{ node.line + 1, node.character }
)
utils.flash_highlight(M.state.code_win, node.line + 1, true)
if vim.fn.hlexists('OutlineJumpHighlight') == 0 then
vim.api.nvim_set_hl(0, 'OutlineJumpHighlight', { link = 'Visual' })
end
utils.flash_highlight(
M.state.code_win,
node.line + 1,
cfg.o.outline_window.jump_highlight_duration,
'OutlineJumpHighlight'
)
if change_focus then
vim.fn.win_gotoid(M.state.code_win)
end

View File

@@ -111,9 +111,12 @@ function M.merge_items_rec(new_node, old_node, index, parent)
end
function M.flash_highlight(winnr, lnum, durationMs, hl_group)
if durationMs == false then
return
end
hl_group = hl_group or "Visual"
if durationMs == true or durationMs == 1 then
durationMs = 300
durationMs = 500
end
local bufnr = vim.api.nvim_win_get_buf(winnr)
local ns = vim.api.nvim_buf_add_highlight(bufnr, 0, hl_group, lnum - 1, 0, -1)