feat: floating window max width/height can be percentages (#553)

This commit is contained in:
abdennourzahaf 2025-01-08 04:07:22 +01:00 committed by GitHub
parent 6290ba1dc2
commit 1df90faf92
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 7 additions and 2 deletions

View file

@ -256,6 +256,7 @@ require("oil").setup({
float = {
-- Padding around the floating window
padding = 2,
-- max_width and max_height can be integers or a float between 0 and 1 (e.g. 0.4 for 40%)
max_width = 0,
max_height = 0,
border = "rounded",

View file

@ -141,6 +141,7 @@ CONFIG *oil-confi
float = {
-- Padding around the floating window
padding = 2,
-- max_width and max_height can be integers or a float between 0 and 1 (e.g. 0.4 for 40%)
max_width = 0,
max_height = 0,
border = "rounded",

View file

@ -124,6 +124,7 @@ local default_config = {
float = {
-- Padding around the floating window
padding = 2,
-- max_width and max_height can be integers or a float between 0 and 1 (e.g. 0.4 for 40%)
max_width = 0,
max_height = 0,
border = "rounded",

View file

@ -115,11 +115,13 @@ M.get_fullscreen_win_opts = function()
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)
local max_width = math.floor(calc_float(config.float.max_width, total_width))
width = math.min(width, max_width)
end
local height = total_height - 2 * config.float.padding
if config.float.max_height > 0 then
height = math.min(height, config.float.max_height)
local max_height = math.floor(calc_float(config.float.max_height, total_height))
height = math.min(height, max_height)
end
local row = math.floor((total_height - height) / 2)
local col = math.floor((total_width - width) / 2) - 1 -- adjust for border width