feat: Move and goto_location simultaneously, and highlight
See readme changes
This commit is contained in:
12
README.md
12
README.md
@@ -61,7 +61,7 @@ keep this list up to date.
|
|||||||
Features/Changes:
|
Features/Changes:
|
||||||
|
|
||||||
- Toggling folds (and added default keymaps for it)
|
- Toggling folds (and added default keymaps for it)
|
||||||
(simrat39/symbols-outline.nvim#194)
|
(simrat39/symbols-outline.nvim#194).
|
||||||
|
|
||||||
- Control focus between outline and code window.
|
- Control focus between outline and code window.
|
||||||
- New commands: SymbolsOutline`Focus,FocusOutline,FocusCode` (see
|
- New commands: SymbolsOutline`Focus,FocusOutline,FocusCode` (see
|
||||||
@@ -71,11 +71,15 @@ Features/Changes:
|
|||||||
- simrat39/symbols-outline.nvim#174
|
- simrat39/symbols-outline.nvim#174
|
||||||
- simrat39/symbols-outline.nvim#207
|
- simrat39/symbols-outline.nvim#207
|
||||||
|
|
||||||
- Cursorline option for the outline window
|
- Cursorline option for the outline window.
|
||||||
|
|
||||||
- Added function and command to show provider and outline window status,
|
- Added function and command to show provider and outline window status,
|
||||||
somewhat like `:LspInfo`.
|
somewhat like `:LspInfo`.
|
||||||
|
|
||||||
|
- Move down/up by one line and peek_location immediately.
|
||||||
|
|
||||||
|
- Flash highlight when using goto/peek location.
|
||||||
|
|
||||||
## Fixes
|
## Fixes
|
||||||
|
|
||||||
- Symbol preview (simrat39/symbols-outline.nvim#176)
|
- Symbol preview (simrat39/symbols-outline.nvim#176)
|
||||||
@@ -378,6 +382,10 @@ local opts = {
|
|||||||
fold_all = "W",
|
fold_all = "W",
|
||||||
unfold_all = "E",
|
unfold_all = "E",
|
||||||
fold_reset = "R",
|
fold_reset = "R",
|
||||||
|
-- Only in this fork:
|
||||||
|
-- Move down/up by one line and peek_location immediately.
|
||||||
|
down_and_goto = '<C-j>',
|
||||||
|
up_and_goto = '<C-k>',
|
||||||
},
|
},
|
||||||
|
|
||||||
-- Lsp clients to ignore
|
-- Lsp clients to ignore
|
||||||
|
|||||||
@@ -116,20 +116,33 @@ function M._current_node()
|
|||||||
return M.state.flattened_outline_items[current_line]
|
return M.state.flattened_outline_items[current_line]
|
||||||
end
|
end
|
||||||
|
|
||||||
function M._goto_location(change_focus)
|
function M.__goto_location(change_focus)
|
||||||
local node = M._current_node()
|
local node = M._current_node()
|
||||||
vim.api.nvim_win_set_cursor(
|
vim.api.nvim_win_set_cursor(
|
||||||
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 change_focus then
|
if change_focus then
|
||||||
vim.fn.win_gotoid(M.state.code_win)
|
vim.fn.win_gotoid(M.state.code_win)
|
||||||
if config.options.auto_close then
|
|
||||||
M.close_outline()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M._goto_location(change_focus)
|
||||||
|
M.__goto_location(change_focus)
|
||||||
|
if change_focus and config.options.auto_close then
|
||||||
|
M.close_outline()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function M._move_and_goto(direction)
|
||||||
|
local move = direction == 'down' and 1 or -1
|
||||||
|
local cur = vim.api.nvim_win_get_cursor(0)
|
||||||
|
cur[1] = cur[1] + move
|
||||||
|
pcall(vim.api.nvim_win_set_cursor, 0, cur)
|
||||||
|
M.__goto_location(false)
|
||||||
|
end
|
||||||
|
|
||||||
function M._toggle_fold(move_cursor, node_index)
|
function M._toggle_fold(move_cursor, node_index)
|
||||||
local node = M.state.flattened_outline_items[node_index] or M._current_node()
|
local node = M.state.flattened_outline_items[node_index] or M._current_node()
|
||||||
local is_folded = folding.is_folded(node)
|
local is_folded = folding.is_folded(node)
|
||||||
@@ -262,10 +275,14 @@ local function setup_keymaps(bufnr)
|
|||||||
map(config.options.keymaps.peek_location, function()
|
map(config.options.keymaps.peek_location, function()
|
||||||
M._goto_location(false)
|
M._goto_location(false)
|
||||||
end)
|
end)
|
||||||
-- -- goto_location of symbol but stay in outline
|
-- Move down/up in outline and peek that location in code
|
||||||
-- map(config.options.keymaps.down_and_goto, function()
|
map(config.options.keymaps.down_and_goto, function()
|
||||||
-- M._move_and_goto(false)
|
M._move_and_goto('down')
|
||||||
-- end)
|
end)
|
||||||
|
-- Move down/up in outline and peek that location in code
|
||||||
|
map(config.options.keymaps.up_and_goto, function()
|
||||||
|
M._move_and_goto('up')
|
||||||
|
end)
|
||||||
-- hover symbol
|
-- hover symbol
|
||||||
map(
|
map(
|
||||||
config.options.keymaps.hover_symbol,
|
config.options.keymaps.hover_symbol,
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ M.defaults = {
|
|||||||
fold_all = 'W',
|
fold_all = 'W',
|
||||||
unfold_all = 'E',
|
unfold_all = 'E',
|
||||||
fold_reset = 'R',
|
fold_reset = 'R',
|
||||||
|
down_and_goto = '<C-j>',
|
||||||
|
up_and_goto = '<C-k>',
|
||||||
},
|
},
|
||||||
lsp_blacklist = {},
|
lsp_blacklist = {},
|
||||||
symbol_blacklist = {},
|
symbol_blacklist = {},
|
||||||
|
|||||||
@@ -110,4 +110,17 @@ M.merge_items_rec = function(new_node, old_node, index, parent)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
M.flash_highlight = function(winnr, lnum, durationMs, hl_group)
|
||||||
|
hl_group = hl_group or "Visual"
|
||||||
|
if durationMs == true or durationMs == 1 then
|
||||||
|
durationMs = 300
|
||||||
|
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)
|
||||||
|
local remove_highlight = function()
|
||||||
|
pcall(vim.api.nvim_buf_clear_namespace, bufnr, ns, 0, -1)
|
||||||
|
end
|
||||||
|
vim.defer_fn(remove_highlight, durationMs)
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
Reference in New Issue
Block a user