From 4574841b7eff3d50ca6517580bf5f3c992645756 Mon Sep 17 00:00:00 2001 From: Joe Meissler Date: Wed, 7 Jun 2023 23:22:57 -0700 Subject: [PATCH] auto_jump config param --- README.md | 2 ++ doc/symbols-outline.txt | 2 ++ lua/symbols-outline.lua | 33 +++++++++++++++++++-------------- lua/symbols-outline/config.lua | 1 + 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 308d9f6..e635853 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ local opts = { relative_width = true, width = 25, auto_close = false, + auto_jump = false, show_numbers = false, show_relative_numbers = false, show_symbol_details = true, @@ -104,6 +105,7 @@ local opts = { | relative_width | Whether width of window is set relative to existing windows | boolean | true | | width | Width of window (as a % or columns based on `relative_width`) | int | 25 | | auto_close | Whether to automatically close the window after selection | boolean | false | +| auto_jump | Whether to automatically jump to the symbol in the source window | boolean | false | | auto_preview | Show a preview of the code on hover | boolean | false | | show_numbers | Shows numbers with the outline | boolean | false | | show_relative_numbers | Shows relative numbers with the outline | boolean | false | diff --git a/doc/symbols-outline.txt b/doc/symbols-outline.txt index 73f9a2f..f9d6b9d 100644 --- a/doc/symbols-outline.txt +++ b/doc/symbols-outline.txt @@ -61,6 +61,7 @@ Pass a table to the setup call above with your configuration options. relative_width = true, width = 25, auto_close = false, + auto_jump = false, show_numbers = false, show_relative_numbers = false, show_symbol_details = true, @@ -126,6 +127,7 @@ Pass a table to the setup call above with your configuration options. │relative_width │Whether width of window is set relative to existing windows │boolean │true │ │width │Width of window (as a % or columns based on relative_width) │int │25 │ │auto_close │Whether to automatically close the window after selection │boolean │false │ +|auto_jump | Whether to automatically jump to the symbol in the source window | boolean | false | │auto_preview │Show a preview of the code on hover │boolean │false │ │show_numbers │Shows numbers with the outline │boolean │false │ │show_relative_numbers │Shows relative numbers with the outline │boolean │false │ diff --git a/lua/symbols-outline.lua b/lua/symbols-outline.lua index 09a5823..d1a1786 100644 --- a/lua/symbols-outline.lua +++ b/lua/symbols-outline.lua @@ -39,20 +39,6 @@ local function setup_global_autocmd() }) 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 = require('symbols-outline.preview').close, - }) - end -end - ------------------------- -- STATE ------------------------- @@ -118,6 +104,25 @@ local function goto_location(change_focus) 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_jump then + goto_location(false) + end + end, + }) + end +end + function M._set_folded(folded, move_cursor, node_index) local node = M.state.flattened_outline_items[node_index] or M._current_node() local changed = (folded ~= folding.is_folded(node)) diff --git a/lua/symbols-outline/config.lua b/lua/symbols-outline/config.lua index 095ca92..cdc4ab2 100644 --- a/lua/symbols-outline/config.lua +++ b/lua/symbols-outline/config.lua @@ -10,6 +10,7 @@ M.defaults = { relative_width = true, width = 25, auto_close = false, + auto_jump = false, auto_preview = false, show_numbers = false, show_relative_numbers = false,