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

@@ -46,6 +46,7 @@ Table of contents
* [Highlights](#highlights) * [Highlights](#highlights)
* [Outline window](#outline-window) * [Outline window](#outline-window)
* [Preview window](#preview-window) * [Preview window](#preview-window)
* [Other highlight groups](#other-highlight-groups)
* [Lua API](#lua-api) * [Lua API](#lua-api)
* [Tips](#tips) * [Tips](#tips)
* [Recipes](#recipes) * [Recipes](#recipes)
@@ -177,6 +178,9 @@ Pass a table to the setup call with your configuration options.
auto_close = false, auto_close = false,
-- Automatically scroll to the location in code when navigating outline window. -- Automatically scroll to the location in code when navigating outline window.
auto_jump = false, auto_jump = false,
-- boolean or integer for milliseconds duration to apply a temporary highlight
-- when jumping. false to disable.
jump_highlight_duration = 300,
-- Vim options for the outline window -- Vim options for the outline window
show_numbers = false, show_numbers = false,
@@ -526,7 +530,7 @@ outline_window = {
}, },
``` ```
Possible highlight groups provided by outline.nvim to customize: Possible highlight groups for the outline window:
| Highlight | Description | | Highlight | Description |
| -------------------- | ---------------------------------------------------- | | -------------------- | ---------------------------------------------------- |
@@ -550,6 +554,15 @@ preview_window = {
}, },
``` ```
### Other highlight groups
| Highlight | Description |
| -------------------- | ---------------------------------------------------------- |
| OutlineJumpHighlight | Used for indicating cursor position when jumping/focusing |
You can also use `outline_window.jump_highlight_duration` to customize in milliseconds,
how long the highlight is applied for.
## Lua API ## Lua API
Outline.nvim provides the following public API for use in lua. Outline.nvim provides the following public API for use in lua.

View File

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

View File

@@ -105,7 +105,17 @@ function M.__goto_location(change_focus)
M.state.code_win, M.state.code_win,
{ node.line + 1, node.character } { 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 if change_focus then
vim.fn.win_gotoid(M.state.code_win) vim.fn.win_gotoid(M.state.code_win)
end end

View File

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