513
513
514
514
--- @param name string
515
515
--- @param height number
516
+ --- @param split_mode string | function | table
516
517
function utils .open_window (name , height , split_mode )
517
518
local cmd_by_split_mode = {
518
519
horizontal = string.format (' %dsplit %s' , height , name ),
@@ -522,7 +523,10 @@ function utils.open_window(name, height, split_mode)
522
523
if cmd_by_split_mode [split_mode ] then
523
524
vim .cmd (cmd_by_split_mode [split_mode ])
524
525
vim .w .org_window_split_mode = split_mode
525
- elseif split_mode == ' auto' then
526
+ return
527
+ end
528
+
529
+ if split_mode == ' auto' then
526
530
local winwidth = utils .winwidth ()
527
531
if (winwidth / 2 ) >= 80 then
528
532
vim .cmd (cmd_by_split_mode .vertical )
@@ -531,13 +535,47 @@ function utils.open_window(name, height, split_mode)
531
535
vim .cmd (cmd_by_split_mode .horizontal )
532
536
vim .w .org_window_split_mode = ' horizontal'
533
537
end
534
- else
535
- if type (split_mode ) == ' function' then
536
- split_mode (name )
537
- else
538
- vim .cmd (string.format (' %s %s' , split_mode , name ))
539
- end
538
+ return
539
+ end
540
+
541
+ if type (split_mode ) == ' function' then
542
+ return split_mode (name )
540
543
end
544
+
545
+ if split_mode == ' float' then
546
+ return utils .open_float (name )
547
+ end
548
+
549
+ if type (split_mode ) == ' table' and split_mode [1 ] == ' float' then
550
+ return utils .open_float (name , split_mode [2 ])
551
+ end
552
+
553
+ return vim .cmd (string.format (' %s %s' , split_mode , name ))
554
+ end
555
+
556
+ --- @param name string
557
+ --- @param scale ? number
558
+ function utils .open_float (name , scale )
559
+ scale = scale or 0.7
560
+ -- Make sure number is between 0 and 1
561
+ scale = math.min (math.max (0 , scale ), 1 )
562
+ local bufnr = vim .api .nvim_create_buf (false , true )
563
+ vim .api .nvim_buf_set_name (bufnr , name )
564
+
565
+ local width = math.floor ((vim .o .columns * scale ))
566
+ local height = math.floor ((vim .o .lines * scale ))
567
+ local row = math.floor ((((vim .o .lines - height ) / 2 ) - 1 ))
568
+ local col = math.floor (((vim .o .columns - width ) / 2 ))
569
+
570
+ vim .api .nvim_open_win (bufnr , true , {
571
+ relative = ' editor' ,
572
+ width = width ,
573
+ height = height ,
574
+ row = row ,
575
+ col = col ,
576
+ style = ' minimal' ,
577
+ border = ' rounded' ,
578
+ })
541
579
end
542
580
543
581
return utils
0 commit comments