@@ -2,6 +2,62 @@ local u = require("gitlab.utils")
22
33local M = {}
44
5+ --- Get the popup view_opts
6+ --- @param title string The string to appear on top of the popup
7+ --- @param user_settings table | nil User-defined popup settings
8+ --- @param width number ? Override default width
9+ --- @param height number ? Override default height
10+ --- @param zindex number ? Override default zindex
11+ --- @return table
12+ M .create_popup_state = function (title , user_settings , width , height , zindex )
13+ local settings = u .merge (require (" gitlab.state" ).settings .popup , user_settings or {})
14+ local view_opts = {
15+ buf_options = {
16+ filetype = " markdown" ,
17+ },
18+ relative = " editor" ,
19+ enter = true ,
20+ focusable = true ,
21+ zindex = zindex or 50 ,
22+ border = {
23+ style = settings .border ,
24+ text = {
25+ top = title ,
26+ },
27+ },
28+ position = settings .position ,
29+ size = {
30+ width = width and math.min (width , vim .o .columns - 2 ) or settings .width ,
31+ height = height and math.min (height , vim .o .lines - 3 ) or settings .height ,
32+ },
33+ opacity = settings .opacity ,
34+ }
35+
36+ return view_opts
37+ end
38+
39+ --- Create view_opts for Box popups used inside popup Layouts
40+ --- @param title string | nil The string to appear on top of the popup
41+ --- @param enter boolean Whether the pop should be focused after creation
42+ --- @param settings table User defined popup settings
43+ --- @return table
44+ M .create_box_popup_state = function (title , enter , settings )
45+ return {
46+ buf_options = {
47+ filetype = " markdown" ,
48+ },
49+ enter = enter or false ,
50+ focusable = true ,
51+ border = {
52+ style = settings .border ,
53+ text = {
54+ top = title ,
55+ },
56+ },
57+ opacity = settings .opacity ,
58+ }
59+ end
60+
561local function exit (popup , opts )
662 if opts .action_before_exit and opts .cb ~= nil then
763 opts .cb ()
@@ -102,7 +158,7 @@ M.set_up_autocommands = function(popup, layout, previous_window, opts)
102158 if layout ~= nil then
103159 layout :update ()
104160 else
105- popup :update_layout (opts and u .create_popup_state (unpack (opts )))
161+ popup :update_layout (opts and M .create_popup_state (unpack (opts )))
106162 end
107163 end )
108164
0 commit comments