Skip to content

Commit

Permalink
'winwidth'/'winheight' are global options
Browse files Browse the repository at this point in the history
  • Loading branch information
MisanthropicBit committed Nov 19, 2024
1 parent 001f909 commit f7295a2
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions lua/winmove/resize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ local neighbor_dir_table = {

---@param dir winmove.Direction
---@param get_dimension_func fun(win_id: integer): integer
---@param min_dimension fun(): integer
---@param min_dimension integer
---@return boolean
local function can_resize(dir, get_dimension_func, min_dimension)
local neighbor_count, applied = layout.apply_to_neighbors(dir, function(neighbor_win_id)
local dimension = get_dimension_func(neighbor_win_id)

return true, dimension <= min_dimension()
return true, dimension <= min_dimension
end)

if neighbor_count == 0 then
-- No neighbors, check the window itself
return get_dimension_func(0) > min_dimension()
return get_dimension_func(0) > min_dimension
end

-- All neighbors are at minimal width/height so we cannot resize
Expand All @@ -49,13 +49,12 @@ end
--- Adjust neighbors in the direction the current window is being resized
---@param dir winmove.Direction
---@param get_dimension fun(win_id: integer): integer
---@param get_min_dimension fun(): integer
---@param min_dimension integer
---@param count integer
---@param anchor winmove.ResizeAnchor
local function adjust_neighbors_in_direction(dir, get_dimension, get_min_dimension, count, anchor)
local function adjust_neighbors_in_direction(dir, get_dimension, min_dimension, count, anchor)
layout.apply_to_neighbors(dir, function(neighbor_win_id)
local dimension = get_dimension(neighbor_win_id)
local min_dimension = get_min_dimension()

if dimension <= min_dimension then
winutil.win_id_context_call(
Expand Down Expand Up @@ -90,29 +89,25 @@ function resize.resize_window(win_id, dir, count, anchor)
end

local horizontal = winutil.is_horizontal(dir)
local is_full_dimension, resize_func, get_dimension, get_min_dimension, edges
local is_full_dimension, resize_func, get_dimension, min_dimension, edges

if horizontal then
is_full_dimension = winutil.is_full_width
resize_func = vim.fn.win_move_separator
get_dimension = vim.api.nvim_win_get_width
get_min_dimension = function()
return math.max(vim.opt_local.winwidth:get(), vim.go.winminwidth)
end
min_dimension = math.max(vim.go.winwidth, vim.go.winminwidth)
edges = { "l", "h" }
else
is_full_dimension = winutil.is_full_height
resize_func = vim.fn.win_move_statusline
get_dimension = vim.api.nvim_win_get_height
get_min_dimension = function()
return math.max(vim.opt_local.winheight:get(), vim.go.winminheight)
end
min_dimension = math.max(vim.go.winheight, vim.go.winminheight)
edges = { "j", "k" }
end

if is_full_dimension(win_id) then
return
elseif not can_resize(dir, get_dimension, get_min_dimension) then
elseif not can_resize(dir, get_dimension, min_dimension) then
return
end

Expand All @@ -132,7 +127,7 @@ function resize.resize_window(win_id, dir, count, anchor)
end

resize_func(win_id, count)
adjust_neighbors_in_direction(dir, get_dimension, get_min_dimension, count, _anchor)
adjust_neighbors_in_direction(dir, get_dimension, min_dimension, count, _anchor)
end

return resize

0 comments on commit f7295a2

Please sign in to comment.