Skip to content

Commit

Permalink
feat: nav view can preview symbol in rightmost column (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Apr 16, 2023
1 parent 7371322 commit 055d220
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lua/aerial/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ local default_options = {
},
-- Jump to symbol in source window when the cursor moves
autojump = false,
-- Show a preview of the code in the right column, when there are no child symbols
preview = false,
-- Keymaps in the nav window
keymaps = {
["<CR>"] = "actions.jump",
Expand Down
21 changes: 19 additions & 2 deletions lua/aerial/nav_view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ local _active_nav = nil
local function create_buf()
local bufnr = vim.api.nvim_create_buf(false, true)
vim.bo[bufnr].buftype = "nofile"
vim.bo[bufnr].bufhidden = "wipe"
vim.bo[bufnr].bufhidden = "hide"
vim.bo[bufnr].swapfile = false
vim.bo[bufnr].modifiable = false
vim.bo[bufnr].filetype = "aerial-nav"
Expand Down Expand Up @@ -211,6 +211,15 @@ local function render_symbols(panel)
panel.height = #lines
end

---@param panel aerial.NavPanel
function AerialNav:preview_symbol(panel)
local symbol = self:get_current_symbol()
if symbol then
vim.api.nvim_win_set_buf(panel.winid, self.bufnr)
navigation.select_symbol(symbol, panel.winid, self.bufnr, { jump = false })
end
end

---@param symbol aerial.Symbol
function AerialNav:focus_symbol(symbol)
local siblings, lnum = get_all_siblings(symbol)
Expand All @@ -220,7 +229,12 @@ function AerialNav:focus_symbol(symbol)

render_symbols(self.left)
render_symbols(self.main)
render_symbols(self.right)
if config.nav.preview and vim.tbl_isempty(self.right.symbols) then
self:preview_symbol(self.right)
else
vim.api.nvim_win_set_buf(self.right.winid, self.right.bufnr)
render_symbols(self.right)
end

if vim.api.nvim_win_is_valid(self.main.winid) then
vim.api.nvim_win_set_cursor(self.main.winid, { lnum, 0 })
Expand Down Expand Up @@ -291,6 +305,9 @@ function AerialNav:close()
for _, id in ipairs(self.autocmds) do
vim.api.nvim_del_autocmd(id)
end
for _, bufnr in ipairs({ self.left.bufnr, self.main.bufnr, self.right.bufnr }) do
vim.api.nvim_buf_delete(bufnr, { force = true })
end
self.autocmds = {}
end

Expand Down

0 comments on commit 055d220

Please sign in to comment.