Merge upstream PR #229

simrat39/symbols-outline.nvim#229
This commit is contained in:
hedy
2023-11-03 09:43:02 +08:00
4 changed files with 51 additions and 4 deletions

View File

@@ -117,7 +117,7 @@ Key:
- ✅ Open handler checks if view is not already open - ✅ Open handler checks if view is not already open
(#235 by eyalz800) (#235 by eyalz800)
- auto_jump config param - auto_goto config param
(#229 by stickperson) (#229 by stickperson)
- ✅ Update nerd fonts to 3.0 - ✅ Update nerd fonts to 3.0
@@ -357,6 +357,8 @@ local opts = {
-- Auto close the outline window if goto_location is triggered and not for -- Auto close the outline window if goto_location is triggered and not for
-- peek_location -- peek_location
auto_close = false, auto_close = false,
-- Automatically go to location in code when navigating outline window
auto_goto = false,
-- Vim options for the outline window -- Vim options for the outline window
show_numbers = false, show_numbers = false,

View File

@@ -132,7 +132,7 @@ Key:
< <
- ✅ Open handler checks if view is not already open (#235 by eyalz800) - ✅ Open handler checks if view is not already open (#235 by eyalz800)
- auto_jump config param (#229 by stickperson) - auto_goto config param (#229 by stickperson)
- ✅ Update nerd fonts to 3.0 (#225 by anstadnik) - ✅ Update nerd fonts to 3.0 (#225 by anstadnik)
- ✅ fix(folding): optimize fold/unfold all (#223 by wjdwndud0114) - ✅ fix(folding): optimize fold/unfold all (#223 by wjdwndud0114)
- ✅ Support markdown setext-style headers (#222 by msr1k) - ✅ Support markdown setext-style headers (#222 by msr1k)
@@ -333,7 +333,9 @@ Default values are shown:
-- Auto close the outline window if goto_location is triggered and not for -- Auto close the outline window if goto_location is triggered and not for
-- peek_location -- peek_location
auto_close = false, auto_close = false,
-- Automatically jump to location in code when navigating outline window
auto_goto = false,
-- Vim options for the outline window -- Vim options for the outline window
show_numbers = false, show_numbers = false,
show_relative_numbers = false, show_relative_numbers = false,
@@ -458,7 +460,6 @@ COMMANDS *symbols-outline-symbols-outline.nvim-commands*
- **:SymbolsOutlineStatus** - **:SymbolsOutlineStatus**
Display current provider and outline window status in the messages area. Display current provider and outline window status in the messages area.
LUA API ~ LUA API ~
>lua >lua

View File

@@ -18,6 +18,7 @@ M.defaults = {
border = 'single', border = 'single',
relative_width = true, relative_width = true,
auto_close = false, auto_close = false,
auto_goto = false,
auto_preview = false, auto_preview = false,
open_hover_on_preview = true, open_hover_on_preview = true,
show_numbers = false, show_numbers = false,

View File

@@ -128,6 +128,7 @@ function M.__goto_location(change_focus)
end end
end end
-- Wraps __goto_location and handles auto_close
function M._goto_location(change_focus) function M._goto_location(change_focus)
M.__goto_location(change_focus) M.__goto_location(change_focus)
if change_focus and config.options.auto_close then if change_focus and config.options.auto_close then
@@ -152,6 +153,48 @@ function M._toggle_fold(move_cursor, node_index)
end end
end end
local function setup_buffer_autocmd()
if config.options.auto_preview then
vim.api.nvim_create_autocmd('CursorHold', {
buffer = 0,
callback = require('symbols-outline.preview').show,
})
else
vim.api.nvim_create_autocmd('CursorMoved', {
buffer = 0,
callback = function()
require('symbols-outline.preview').close()
if config.options.auto_goto then
M._goto_location(false)
end
end,
})
end
end
local function setup_buffer_autocmd()
if config.options.auto_preview then
vim.api.nvim_create_autocmd('CursorMoved', {
buffer = 0,
callback = require('symbols-outline.preview').show,
})
else
vim.api.nvim_create_autocmd('CursorMoved', {
buffer = 0,
callback = require('symbols-outline.preview').close,
})
end
if config.options.auto_goto then
vim.api.nvim_create_autocmd('CursorMoved', {
buffer = 0,
callback = function()
-- Don't use _goto_location because we don't want to auto-close
M.__goto_location(false)
end
})
end
end
function M._set_folded(folded, move_cursor, node_index) function M._set_folded(folded, 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 changed = (folded ~= folding.is_folded(node)) local changed = (folded ~= folding.is_folded(node))