feat: Focus and unfocus outline window
This commit is contained in:
25
README.md
25
README.md
@@ -34,12 +34,23 @@ Below is a list of features I've included in this fork which, at the time of
|
||||
writing, has not been included upstream (in the original repo). I try my best to
|
||||
keep this list up to date.
|
||||
|
||||
Features:
|
||||
|
||||
- Feat: Toggling folds (and added default keymaps for it)
|
||||
(simrat39/symbols-outline.nvim#194)
|
||||
- Feat: Control focus between outline and code window.
|
||||
- New commands: SymbolsOutline`Focus,FocusOutline,FocusCode` (see
|
||||
[commands](#commands))
|
||||
- Fixed issues:
|
||||
- simrat39/symbols-outline.nvim#143
|
||||
- simrat39/symbols-outline.nvim#174
|
||||
- simrat39/symbols-outline.nvim#207
|
||||
- Feat: when `auto_close=true` only auto close if `goto_location` is used (where
|
||||
focus changed), and not for `focus_location` (simrat39/symbols-outline.nvim#119)
|
||||
- Feat: Cursorline option for the outline window
|
||||
|
||||
Fixes:
|
||||
|
||||
- Fix symbol preview (simrat39/symbols-outline.nvim#176)
|
||||
- Fix `SymbolsOutlineClose` crashing when already closed: simrat39/symbols-outline.nvim#163
|
||||
- Support Nerd fonts v3.0: simrat39/symbols-outline.nvim#225
|
||||
@@ -239,6 +250,11 @@ local opts = {
|
||||
auto_unfold_hover = true,
|
||||
fold_markers = { '', '' },
|
||||
wrap = false,
|
||||
-- Only in this fork:
|
||||
-- Whether to focus on the outline window when it is opened.
|
||||
-- Set to false to remain focus on your previous buffer when opening
|
||||
-- symbols-outline.
|
||||
focus_on_open = true,
|
||||
keymaps = { -- These keymaps can be a string or a table for multiple keys
|
||||
close = {"<Esc>", "q"},
|
||||
goto_location = "<Cr>",
|
||||
@@ -318,14 +334,18 @@ local opts = {
|
||||
| auto_unfold_hover | Automatically unfold hovered symbol | boolean | true |
|
||||
| fold_markers | Markers to denote foldable symbol's status | table (array) | { '', '' } |
|
||||
| wrap | Whether to wrap long lines, or let them flow off the window | boolean | false |
|
||||
| focus_on_open | Whether to focus cursor on the outline window when opening | boolean | true |
|
||||
|
||||
## Commands
|
||||
|
||||
| Command | Description |
|
||||
| ---------------------- | ---------------------- |
|
||||
| ----------------------------- | -------------------------------- |
|
||||
| `:SymbolsOutline` | Toggle symbols outline |
|
||||
| `:SymbolsOutlineOpen` | Open symbols outline |
|
||||
| `:SymbolsOutlineClose` | Close symbols outline |
|
||||
| `:SymbolsOutlineFocus` | Toggle focus on symbols outline |
|
||||
| `:SymbolsOutlineFocusOutline` | Focus on symbols outline |
|
||||
| `:SymbolsOutlineFocusCode` | Focus on source window |
|
||||
|
||||
### Lua
|
||||
|
||||
@@ -333,6 +353,9 @@ local opts = {
|
||||
require'symbols-outline'.toggle_outline()
|
||||
require'symbols-outline'.open_outline()
|
||||
require'symbols-outline'.close_outline()
|
||||
require'symbols-outline'.focus_toggle()
|
||||
require'symbols-outline'.focus_outline()
|
||||
require'symbols-outline'.focus_code()
|
||||
```
|
||||
|
||||
## Default keymaps
|
||||
|
||||
@@ -57,6 +57,9 @@ local function setup_commands()
|
||||
vim.api.nvim_create_user_command('SymbolsOutline', M.toggle_outline, { nargs = 0 })
|
||||
vim.api.nvim_create_user_command('SymbolsOutlineOpen', M.open_outline, { nargs = 0 })
|
||||
vim.api.nvim_create_user_command('SymbolsOutlineClose', M.close_outline, { nargs = 0 })
|
||||
vim.api.nvim_create_user_command('SymbolsOutlineFocusOutline', M.focus_outline, { nargs = 0 })
|
||||
vim.api.nvim_create_user_command('SymbolsOutlineFocusCode', M.focus_code, { nargs = 0 })
|
||||
vim.api.nvim_create_user_command('SymbolsOutlineFocus', M.focus_toggle, { nargs = 0 })
|
||||
end
|
||||
|
||||
-------------------------
|
||||
@@ -337,6 +340,10 @@ local function handler(response)
|
||||
writer.parse_and_write(M.view.bufnr, M.state.flattened_outline_items)
|
||||
|
||||
M._highlight_current_item(M.state.code_win)
|
||||
|
||||
if not config.options.focus_on_open then
|
||||
vim.fn.win_gotoid(M.state.code_win)
|
||||
end
|
||||
end
|
||||
|
||||
function M.toggle_outline()
|
||||
@@ -357,6 +364,29 @@ function M.close_outline()
|
||||
M.view:close()
|
||||
end
|
||||
|
||||
function M.focus_outline()
|
||||
if M.view:is_open() then
|
||||
vim.fn.win_gotoid(M.view.winnr)
|
||||
end
|
||||
end
|
||||
|
||||
function M.focus_code()
|
||||
if M.state.code_win then
|
||||
vim.fn.win_gotoid(M.state.code_win)
|
||||
end
|
||||
end
|
||||
|
||||
function M.focus_toggle()
|
||||
if M.view:is_open() and M.state.code_win then
|
||||
local winid = vim.fn.win_getid()
|
||||
if winid == M.state.code_win then
|
||||
vim.fn.win_gotoid(M.view.winnr)
|
||||
else
|
||||
vim.fn.win_gotoid(M.state.code_win)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
config.setup(opts)
|
||||
ui.setup_highlights()
|
||||
|
||||
@@ -21,6 +21,7 @@ M.defaults = {
|
||||
auto_unfold_hover = true,
|
||||
fold_markers = { '', '' },
|
||||
wrap = false,
|
||||
focus_on_open = true,
|
||||
keymaps = { -- These keymaps can be a string or a table for multiple keys
|
||||
close = { '<Esc>', 'q' },
|
||||
goto_location = '<Cr>',
|
||||
|
||||
Reference in New Issue
Block a user