@@ -548,6 +548,34 @@ function M.reset_winhl()
548
548
end
549
549
end
550
550
551
+ --- Check if width determined or calculated on-fly
552
+ --- @return boolean
553
+ function M .is_width_determined ()
554
+ return type (M .View .width ) ~= " function"
555
+ end
556
+
557
+ --- Configure width-related config
558
+ --- @param width string | function | number | table | nil
559
+ function M .configure_width (width )
560
+ if type (width ) == " table" then
561
+ M .View .adaptive_size = true
562
+ M .View .width = width .min or DEFAULT_MIN_WIDTH
563
+ M .View .max_width = width .max or DEFAULT_MAX_WIDTH
564
+ M .View .padding = width .padding or DEFAULT_PADDING
565
+ elseif width == nil then
566
+ if M .config .width ~= nil then
567
+ -- if we had input config - fallback to it
568
+ M .configure_width (M .config .width )
569
+ else
570
+ -- otherwise - restore initial width
571
+ M .View .width = M .View .initial_width
572
+ end
573
+ else
574
+ M .View .adaptive_size = false
575
+ M .View .width = width
576
+ end
577
+ end
578
+
551
579
function M .setup (opts )
552
580
local options = opts .view or {}
553
581
M .View .centralize_selection = options .centralize_selection
@@ -563,15 +591,8 @@ function M.setup(opts)
563
591
M .View .float = options .float
564
592
M .on_attach = opts .on_attach
565
593
566
- if type (options .width ) == " table" then
567
- M .View .adaptive_size = true
568
- M .View .width = options .width .min or DEFAULT_MIN_WIDTH
569
- M .View .max_width = options .width .max or DEFAULT_MAX_WIDTH
570
- M .View .padding = options .width .padding or DEFAULT_PADDING
571
- else
572
- M .View .adaptive_size = false
573
- M .View .width = options .width
574
- end
594
+ M .config = options
595
+ M .configure_width (options .width )
575
596
576
597
M .View .initial_width = get_width ()
577
598
end
0 commit comments