Skip to content

Commit

Permalink
feat: new option layout.preserve_equality to keep window sizes equal (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Dec 15, 2022
1 parent a95b63f commit 65ca35c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
3 changes: 3 additions & 0 deletions lua/aerial/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ local default_options = {
-- edge - open aerial at the far right/left of the editor
-- window - open aerial to the right/left of the current window
placement = "window",

-- Preserve window size equality with (:help CTRL-W_=)
preserve_equality = false,
},

-- Determines how the aerial window decides which buffer to display symbols for
Expand Down
3 changes: 3 additions & 0 deletions lua/aerial/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ local function resize_all_wins(aer_bufnr, preferred_width, preferred_height)
end
end
end
if config.layout.preserve_equality then
vim.cmd.wincmd({ args = { "=" } })
end
return max_width
end

Expand Down
38 changes: 22 additions & 16 deletions lua/aerial/window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ local function setup_aerial_win(src_winid, aer_winid, aer_bufnr)
-- Set the filetype only after we enter the buffer so that ftplugins behave properly
vim.api.nvim_buf_set_option(aer_bufnr, "filetype", "aerial")
util.restore_width(aer_winid, aer_bufnr)
if config.layout.preserve_equality then
vim.cmd.wincmd({ args = { "=" } })
end
end

local function create_aerial_window(bufnr, aer_bufnr, direction, existing_win)
Expand Down Expand Up @@ -220,28 +223,31 @@ end
M.close = function()
if util.is_aerial_buffer() then
vim.api.nvim_win_close(0, false)
return
end
local aer_win = util.get_aerial_win()
if aer_win then
vim.api.nvim_win_close(aer_win, false)
else
-- No aerial buffer for this buffer.
local backend = backends.get(0)
-- If this buffer has no supported symbols backend or no symbols,
-- look for other aerial windows and close the first
if backend == nil or not data.has_symbols(0) then
for _, winid in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
if vim.api.nvim_win_is_valid(winid) then
local winbuf = vim.api.nvim_win_get_buf(winid)
if util.is_aerial_buffer(winbuf) then
vim.api.nvim_win_close(winid, false)
break
local aer_win = util.get_aerial_win()
if aer_win then
vim.api.nvim_win_close(aer_win, false)
else
-- No aerial buffer for this buffer.
local backend = backends.get(0)
-- If this buffer has no supported symbols backend or no symbols,
-- look for other aerial windows and close the first
if backend == nil or not data.has_symbols(0) then
for _, winid in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
if vim.api.nvim_win_is_valid(winid) then
local winbuf = vim.api.nvim_win_get_buf(winid)
if util.is_aerial_buffer(winbuf) then
vim.api.nvim_win_close(winid, false)
break
end
end
end
end
end
end
if config.layout.preserve_equality then
vim.cmd.wincmd({ args = { "=" } })
end
end

M.close_all = function()
Expand Down

0 comments on commit 65ca35c

Please sign in to comment.