Skip to content

Commit d6a977b

Browse files
author
Bassam Data
committed
fix(selecta): fix max height when you have percentage
1 parent 24a3c34 commit d6a977b

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

lua/namu/selecta/selecta.lua

+11-10
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,12 @@ local function calculate_window_size(items, opts, formatter)
383383
local row_position = opts.row_position
384384
local lines = vim.o.lines
385385
local max_available_height
386-
if row_position == "top10" or row_position == "top10_right" then
387-
max_available_height = lines - math.floor(lines * 0.1) - vim.o.cmdheight - 4
388-
elseif row_position == "bottom" then
386+
local position_info = parse_position(row_position)
387+
388+
if position_info.type:match("^top") then
389+
-- Handle any top position (top, top_right, with any percentage)
390+
max_available_height = lines - math.floor(lines * position_info.ratio) - vim.o.cmdheight - 4
391+
elseif position_info.type == "bottom" then
389392
max_available_height = math.floor(vim.o.lines * 0.2)
390393
else
391394
max_available_height = lines - math.floor(lines / 2) - 4
@@ -748,22 +751,20 @@ local function resize_window(state, opts)
748751
if not (state.active and vim.api.nvim_win_is_valid(state.win)) then
749752
return
750753
end
751-
752754
-- Calculate new dimensions based on filtered items
753755
local new_width, new_height = calculate_window_size(state.filtered_items, opts, opts.formatter)
754-
755-
-- Get current window config
756756
local current_config = vim.api.nvim_win_get_config(state.win)
757-
758757
-- Calculate maximum height based on available space below the initial row
759758
local max_available_height
760-
if opts.row_position == "top10" or M.config.row_position == "top10" then
761-
max_available_height = vim.o.lines - math.floor(vim.o.lines * 0.1) - vim.o.cmdheight - 4 -- Leave some space for status line
759+
local row_position = opts.row_position or M.config.row_position
760+
local position_info = parse_position(row_position)
761+
if position_info.type:match("^top") then
762+
-- Handle any top position (top, top_right, with any percentage)
763+
max_available_height = vim.o.lines - math.floor(vim.o.lines * position_info.ratio) - vim.o.cmdheight - 4
762764
else
763765
max_available_height = vim.o.lines - state.row - vim.o.cmdheight - 4 -- Leave some space for status line
764766
end
765767
new_height = math.min(new_height, max_available_height)
766-
767768
-- print(
768769
-- string.format(
769770
-- "Resizing window: row=%d, col=%d, width=%d, height=%d, max_available_height=%d, num_items=%d",

0 commit comments

Comments
 (0)