feat: add layout.resize_to_content config option

This commit is contained in:
Steven Arcangeli 2023-06-21 09:13:12 -07:00
parent 8b57371225
commit c4714a6e37
4 changed files with 13 additions and 19 deletions

View file

@ -26,6 +26,9 @@ local default_options = {
-- window - open aerial to the right/left of the current window
placement = "window",
-- When the symbols change, resize the aerial window (within min/max constraints) to fit
resize_to_content = true,
-- Preserve window size equality with (:help CTRL-W_=)
preserve_equality = false,
},

View file

@ -42,8 +42,10 @@ local function resize_all_wins(aer_bufnr, preferred_width, preferred_height)
-- padding out whitespace. The gutter needs to adjust the total window
-- size, but it doesn't take space away from the content.
max_width = math.max(max_width, width - gutter)
vim.api.nvim_win_set_width(winid, width)
util.save_width(aer_bufnr, width)
if config.layout.resize_to_content or vim.b[aer_bufnr].aerial_width == nil then
vim.api.nvim_win_set_width(winid, width)
end
vim.b[aer_bufnr].aerial_width = width
-- Reposition floating windows
if util.is_floating_win(winid) then

View file

@ -28,22 +28,8 @@ end
---@param str string
---@return string
M.remove_newlines = function(str)
return string.gsub(str, "\n", " ")
end
---@param winid integer Window to restore
---@param bufnr integer Aerial buffer
M.restore_width = function(winid, bufnr)
local ok, width = pcall(vim.api.nvim_buf_get_var, bufnr, "aerial_width")
if ok then
vim.api.nvim_win_set_width(winid, width)
end
end
---@param bufnr integer
---@param width integer
M.save_width = function(bufnr, width)
vim.api.nvim_buf_set_var(bufnr, "aerial_width", width)
local ret = string.gsub(str, "\n", " ")
return ret
end
---@param winid nil|integer

View file

@ -107,7 +107,10 @@ local function setup_aerial_win(src_winid, aer_winid, aer_bufnr)
vim.api.nvim_win_set_var(src_winid, "aerial_win", aer_winid)
-- 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)
local width = vim.b[aer_bufnr].aerial_width
if width then
vim.api.nvim_win_set_width(aer_winid, width)
end
if config.layout.preserve_equality then
vim.cmd.wincmd({ args = { "=" } })
end