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:
15
README.md
15
README.md
@@ -46,6 +46,7 @@ Table of contents
|
||||
* [Highlights](#highlights)
|
||||
* [Outline window](#outline-window)
|
||||
* [Preview window](#preview-window)
|
||||
* [Other highlight groups](#other-highlight-groups)
|
||||
* [Lua API](#lua-api)
|
||||
* [Tips](#tips)
|
||||
* [Recipes](#recipes)
|
||||
@@ -177,6 +178,9 @@ Pass a table to the setup call with your configuration options.
|
||||
auto_close = false,
|
||||
-- Automatically scroll to the location in code when navigating outline window.
|
||||
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
|
||||
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 |
|
||||
| -------------------- | ---------------------------------------------------- |
|
||||
@@ -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
|
||||
|
||||
Outline.nvim provides the following public API for use in lua.
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user