Skip to content

Commit

Permalink
feat: horizontal/vertical padding
Browse files Browse the repository at this point in the history
  • Loading branch information
ilzayn committed Dec 20, 2024
1 parent dba0375 commit a7779b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
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

0 comments on commit a7779b5

Please sign in to comment.