Skip to content

Commit

Permalink
feat: floating window max width/height can be percentages (#553)
Browse files Browse the repository at this point in the history
  • Loading branch information
abdennourzahaf authored Jan 8, 2025
1 parent 6290ba1 commit 1df90fa
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions doc/oil.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions lua/oil/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions lua/oil/layout.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1df90fa

Please sign in to comment.