Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: horizontal/vertical padding #540

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lua/oil/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ local default_config = {
-- Configuration for the floating window in oil.open_float
float = {
-- Padding around the floating window
-- Accepts a number for padding to be the same on each side
-- OR a table with { horizontal = number, vertical = number }
padding = 2,
max_width = 0,
max_height = 0,
Expand Down Expand Up @@ -364,8 +366,12 @@ local M = {}
---@class (exact) oil.SetupProgressWindowConfig : oil.SetupWindowConfig
---@field minimized_border? string|string[] The border for the minimized progress window

---@class (exact) oil.FloatWindowPaddingConfig
---@field horizontal integer
---@field vertical integer

---@class (exact) oil.FloatWindowConfig
---@field padding integer
---@field padding integer|oil.FloatWindowPaddingConfig
---@field max_width integer
---@field max_height integer
---@field border string|string[]
Expand Down Expand Up @@ -427,6 +433,14 @@ M.setup = function(opts)
new_conf.watch_for_changes = true
end

-- If a number was given it is changed so no error is produced
if type(new_conf.float.padding) ~= "table" then
new_conf.float.padding = {
horizontal = new_conf.float.padding,
vertical = new_conf.float.padding
}
end

for k, v in pairs(new_conf) do
M[k] = v
end
Expand Down
4 changes: 2 additions & 2 deletions lua/oil/layout.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ M.get_fullscreen_win_opts = function()

local total_width = M.get_editor_width()
local total_height = M.get_editor_height()
local width = total_width - 2 * config.float.padding
local width = total_width - 2 * config.float.padding.horizontal
if config.float.border ~= "none" then
width = width - 2 -- The border consumes 1 col on each side
end
if config.float.max_width > 0 then
width = math.min(width, config.float.max_width)
end
local height = total_height - 2 * config.float.padding
local height = total_height - 2 * config.float.padding.vertical
if config.float.max_height > 0 then
height = math.min(height, config.float.max_height)
end
Expand Down
Loading