feat(commands): Support bang on commands to force retain focus
See readme
This commit is contained in:
1
.github/workflows/panvimdoc.yml
vendored
1
.github/workflows/panvimdoc.yml
vendored
@@ -12,6 +12,7 @@ jobs:
|
|||||||
uses: kdheepak/panvimdoc@main
|
uses: kdheepak/panvimdoc@main
|
||||||
with:
|
with:
|
||||||
vimdoc: symbols-outline
|
vimdoc: symbols-outline
|
||||||
|
version: "NVIM v0.7.0"
|
||||||
- uses: stefanzweifel/git-auto-commit-action@v4
|
- uses: stefanzweifel/git-auto-commit-action@v4
|
||||||
with:
|
with:
|
||||||
commit_message: "Auto generate vim docs"
|
commit_message: "Auto generate vim docs"
|
||||||
|
|||||||
79
README.md
79
README.md
@@ -239,13 +239,17 @@ local opts = {
|
|||||||
position = 'right',
|
position = 'right',
|
||||||
relative_width = true,
|
relative_width = true,
|
||||||
width = 25,
|
width = 25,
|
||||||
|
|
||||||
-- Behaviour changed in this fork:
|
-- Behaviour changed in this fork:
|
||||||
-- 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
|
||||||
-- focus_location
|
-- focus_location
|
||||||
auto_close = false,
|
auto_close = false,
|
||||||
|
|
||||||
|
-- Vim options for the outline window
|
||||||
show_numbers = false,
|
show_numbers = false,
|
||||||
show_relative_numbers = false,
|
show_relative_numbers = false,
|
||||||
show_cursorline = true,
|
show_cursorline = true,
|
||||||
|
|
||||||
show_symbol_details = true,
|
show_symbol_details = true,
|
||||||
-- Highlight group for the preview background
|
-- Highlight group for the preview background
|
||||||
preview_bg_highlight = 'Pmenu',
|
preview_bg_highlight = 'Pmenu',
|
||||||
@@ -253,11 +257,13 @@ local opts = {
|
|||||||
auto_unfold_hover = true,
|
auto_unfold_hover = true,
|
||||||
fold_markers = { '', '' },
|
fold_markers = { '', '' },
|
||||||
wrap = false,
|
wrap = false,
|
||||||
|
|
||||||
-- Only in this fork:
|
-- Only in this fork:
|
||||||
-- Whether to focus on the outline window when it is opened.
|
-- Whether to focus on the outline window when it is opened.
|
||||||
-- Set to false to remain focus on your previous buffer when opening
|
-- Set to false to remain focus on your previous buffer when opening
|
||||||
-- symbols-outline.
|
-- symbols-outline.
|
||||||
focus_on_open = true,
|
focus_on_open = true,
|
||||||
|
|
||||||
keymaps = { -- These keymaps can be a string or a table for multiple keys
|
keymaps = { -- These keymaps can be a string or a table for multiple keys
|
||||||
close = {"<Esc>", "q"},
|
close = {"<Esc>", "q"},
|
||||||
-- Jump to symbol under cursor
|
-- Jump to symbol under cursor
|
||||||
@@ -278,8 +284,10 @@ local opts = {
|
|||||||
unfold_all = "E",
|
unfold_all = "E",
|
||||||
fold_reset = "R",
|
fold_reset = "R",
|
||||||
},
|
},
|
||||||
|
|
||||||
lsp_blacklist = {},
|
lsp_blacklist = {},
|
||||||
symbol_blacklist = {},
|
symbol_blacklist = {},
|
||||||
|
|
||||||
symbols = {
|
symbols = {
|
||||||
-- Changed in this fork
|
-- Changed in this fork
|
||||||
File = { icon = "", hl = "@text.uri" },
|
File = { icon = "", hl = "@text.uri" },
|
||||||
@@ -345,14 +353,34 @@ local opts = {
|
|||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
|
||||||
| Command | Description |
|
- **:SymbolsOutline[!]**
|
||||||
| ----------------------------- | -------------------------------- |
|
|
||||||
| `:SymbolsOutline` | Toggle symbols outline |
|
Toggle symbols outline. With bang (`!`) the cursor focus stays in your original
|
||||||
| `:SymbolsOutlineOpen` | Open symbols outline |
|
window after opening the outline window. Set `focus_on_win = true` to always use
|
||||||
| `:SymbolsOutlineClose` | Close symbols outline |
|
this behaviour.
|
||||||
| `:SymbolsOutlineFocus` | Toggle focus on symbols outline |
|
|
||||||
| `:SymbolsOutlineFocusOutline` | Focus on symbols outline |
|
- **:SymbolsOutlineOpen[!]**
|
||||||
| `:SymbolsOutlineFocusCode` | Focus on source window |
|
|
||||||
|
Open symbols outline. With bang (`!`) the cursor focus stays in your original
|
||||||
|
window after opening the outline window. Set `focus_on_win = true` to always use
|
||||||
|
this behaviour.
|
||||||
|
|
||||||
|
- **:SymbolsOutlineClose**
|
||||||
|
|
||||||
|
Close symbols outline
|
||||||
|
|
||||||
|
- **:SymbolsOutlineFocus**
|
||||||
|
|
||||||
|
Toggle focus on symbols outline
|
||||||
|
|
||||||
|
- **:SymbolsOutlineFocusOutline**
|
||||||
|
|
||||||
|
Focus on symbols outline
|
||||||
|
|
||||||
|
- **:SymbolsOutlineFocusCode**
|
||||||
|
|
||||||
|
Focus on source window
|
||||||
|
|
||||||
|
|
||||||
### Lua API
|
### Lua API
|
||||||
|
|
||||||
@@ -360,13 +388,40 @@ local opts = {
|
|||||||
require'symbols-outline'
|
require'symbols-outline'
|
||||||
```
|
```
|
||||||
- setup(opts)
|
- setup(opts)
|
||||||
- toggle_outline()
|
|
||||||
- open_outline()
|
- toggle_outline(opts)
|
||||||
|
|
||||||
|
Toggle opening/closing of outline window.
|
||||||
|
|
||||||
|
If `opts.bang` is true, keep focus on previous window.
|
||||||
|
|
||||||
|
- open_outline(opts)
|
||||||
|
|
||||||
|
Open the outline window.
|
||||||
|
|
||||||
|
If `opts.bang` is true, keep focus on previous window.
|
||||||
|
|
||||||
- close_outline()
|
- close_outline()
|
||||||
|
|
||||||
|
Close the outline window
|
||||||
|
|
||||||
- focus_toggle()
|
- focus_toggle()
|
||||||
|
|
||||||
|
Toggle cursor focus between code and outline window
|
||||||
|
|
||||||
- focus_outline()
|
- focus_outline()
|
||||||
|
|
||||||
|
Focus cursor on the outline window.
|
||||||
|
|
||||||
- focus_code()
|
- focus_code()
|
||||||
|
|
||||||
|
Focus cursor on the window which the outline is derived from.
|
||||||
|
|
||||||
|
- is_open()
|
||||||
|
|
||||||
|
Return whether the outline window is open
|
||||||
|
|
||||||
|
|
||||||
## Default keymaps
|
## Default keymaps
|
||||||
|
|
||||||
| Key | Action |
|
| Key | Action |
|
||||||
@@ -379,8 +434,8 @@ require'symbols-outline'
|
|||||||
| r | Rename symbol |
|
| r | Rename symbol |
|
||||||
| a | Code actions |
|
| a | Code actions |
|
||||||
| h | fold symbol |
|
| h | fold symbol |
|
||||||
| tab | toggle fold under cursor |
|
| Tab | toggle fold under cursor |
|
||||||
| shift+tab | toggle all folds |
|
| Shift+Tab | toggle all folds |
|
||||||
| l | Unfold symbol |
|
| l | Unfold symbol |
|
||||||
| W | Fold all symbols |
|
| W | Fold all symbols |
|
||||||
| E | Unfold all symbols |
|
| E | Unfold all symbols |
|
||||||
|
|||||||
@@ -54,12 +54,13 @@ local function setup_buffer_autocmd()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function setup_commands()
|
local function setup_commands()
|
||||||
vim.api.nvim_create_user_command('SymbolsOutline', M.toggle_outline, { nargs = 0 })
|
local cmd = function(n, c, o) vim.api.nvim_create_user_command('SymbolsOutline'..n, c, o) end
|
||||||
vim.api.nvim_create_user_command('SymbolsOutlineOpen', M.open_outline, { nargs = 0 })
|
cmd('', M.toggle_outline, { nargs = 0, bang = true })
|
||||||
vim.api.nvim_create_user_command('SymbolsOutlineClose', M.close_outline, { nargs = 0 })
|
cmd('Open', M.open_outline, { nargs = 0, bang = true })
|
||||||
vim.api.nvim_create_user_command('SymbolsOutlineFocusOutline', M.focus_outline, { nargs = 0 })
|
cmd('Close', M.close_outline, { nargs = 0 })
|
||||||
vim.api.nvim_create_user_command('SymbolsOutlineFocusCode', M.focus_code, { nargs = 0 })
|
cmd('FocusOutline', M.focus_outline, { nargs = 0 })
|
||||||
vim.api.nvim_create_user_command('SymbolsOutlineFocus', M.focus_toggle, { nargs = 0 })
|
cmd('FocusCode', M.focus_code, { nargs = 0 })
|
||||||
|
cmd('Focus', M.focus_toggle, { nargs = 0 })
|
||||||
end
|
end
|
||||||
|
|
||||||
-------------------------
|
-------------------------
|
||||||
@@ -69,10 +70,11 @@ M.state = {
|
|||||||
outline_items = {},
|
outline_items = {},
|
||||||
flattened_outline_items = {},
|
flattened_outline_items = {},
|
||||||
code_win = 0,
|
code_win = 0,
|
||||||
|
opts = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
local function wipe_state()
|
local function wipe_state()
|
||||||
M.state = { outline_items = {}, flattened_outline_items = {}, code_win = 0 }
|
M.state = { outline_items = {}, flattened_outline_items = {}, code_win = 0, opts = {} }
|
||||||
end
|
end
|
||||||
|
|
||||||
local function _update_lines()
|
local function _update_lines()
|
||||||
@@ -341,21 +343,22 @@ local function handler(response)
|
|||||||
|
|
||||||
M._highlight_current_item(M.state.code_win)
|
M._highlight_current_item(M.state.code_win)
|
||||||
|
|
||||||
if not config.options.focus_on_open then
|
if not config.options.focus_on_open or (M.state.opts and M.state.opts.bang) then
|
||||||
vim.fn.win_gotoid(M.state.code_win)
|
vim.fn.win_gotoid(M.state.code_win)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.toggle_outline()
|
function M.toggle_outline(opts)
|
||||||
if M.view:is_open() then
|
if M.view:is_open() then
|
||||||
M.close_outline()
|
M.close_outline()
|
||||||
else
|
else
|
||||||
M.open_outline()
|
M.open_outline(opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.open_outline()
|
function M.open_outline(opts)
|
||||||
if not M.view:is_open() then
|
if not M.view:is_open() then
|
||||||
|
M.state.opts = opts
|
||||||
providers.request_symbols(handler)
|
providers.request_symbols(handler)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -387,6 +390,10 @@ function M.focus_toggle()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.is_open()
|
||||||
|
return M.view:is_open()
|
||||||
|
end
|
||||||
|
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
config.setup(opts)
|
config.setup(opts)
|
||||||
ui.setup_highlights()
|
ui.setup_highlights()
|
||||||
|
|||||||
Reference in New Issue
Block a user