@@ -14,7 +14,7 @@ local M = {}
1414local uid_counter = 0
1515
1616--- @alias PanelConfig PanelFloatSpec | PanelSplitSpec
17- --- @alias PanelType ' "split"' | ' "float"'
17+ --- @alias PanelType " split" | " float"
1818
1919--- @type PerfTimer
2020local perf = PerfTimer (" [Panel] redraw" )
@@ -68,8 +68,8 @@ Panel.default_type = "split"
6868--- @field position " left" | " top" | " right" | " bottom"
6969--- @field relative " editor" | " win"
7070--- @field win integer
71- --- @field width integer
72- --- @field height integer
71+ --- @field width ? integer
72+ --- @field height ? integer
7373--- @field win_opts WindowOptions
7474
7575--- @type PanelSplitSpec
@@ -249,7 +249,7 @@ function Panel:resize()
249249 if config .type == " split" then
250250 if self .state .form == " column" and config .width then
251251 api .nvim_win_set_width (self .winid , config .width )
252- elseif config .height then
252+ elseif self . state . form == " row " and config .height then
253253 api .nvim_win_set_height (self .winid , config .height )
254254 end
255255 elseif config .type == " float" then
@@ -487,22 +487,70 @@ function Panel:get_default_config(panel_type)
487487 return config
488488end
489489
490- --- @return integer
490+ --- @return integer ?
491491function Panel :get_width ()
492492 if self :is_open () then
493493 return api .nvim_win_get_width (self .winid )
494494 end
495-
496- return - 1
497495end
498496
499- --- @return integer
497+ --- @return integer ?
500498function Panel :get_height ()
501499 if self :is_open () then
502500 return api .nvim_win_get_height (self .winid )
503501 end
502+ end
503+
504+ function Panel :infer_width ()
505+ local cur_width = self :get_width ()
506+ if cur_width then return cur_width end
507+
508+ local config = self :get_config ()
509+ if config .width then return config .width end
510+
511+ -- PanelFloatSpec requires both width and height to be defined. If we get
512+ -- here then the panel is a split.
513+ --- @cast config PanelSplitSpec
514+
515+ if config .win and api .nvim_win_is_valid (config .win ) then
516+ if self .state .form == " row" then
517+ return api .nvim_win_get_width (config .win )
518+ elseif self .state .form == " column" then
519+ return math.floor (api .nvim_win_get_width (config .win ) / 2 )
520+ end
521+ end
522+
523+ if self .state .form == " row" then
524+ return vim .o .columns
525+ end
526+
527+ return math.floor (vim .o .columns / 2 )
528+ end
529+
530+ function Panel :infer_height ()
531+ local cur_height = self :get_height ()
532+ if cur_height then return cur_height end
533+
534+ local config = self :get_config ()
535+ if config .height then return config .height end
536+
537+ -- PanelFloatSpec requires both width and height to be defined. If we get
538+ -- here then the panel is a split.
539+ --- @cast config PanelSplitSpec
540+
541+ if config .win and api .nvim_win_is_valid (config .win ) then
542+ if self .state .form == " row" then
543+ return math.floor (api .nvim_win_get_height (config .win ) / 2 )
544+ elseif self .state .form == " column" then
545+ return api .nvim_win_get_height (config .win )
546+ end
547+ end
548+
549+ if self .state .form == " row" then
550+ return math.floor (vim .o .lines / 2 )
551+ end
504552
505- return - 1
553+ return vim . o . lines
506554end
507555
508556function Panel .next_uid ()
0 commit comments