Skip to content

Commit 59f3e52

Browse files
committed
refactor: move helper functions to popup module
1 parent dc8e505 commit 59f3e52

File tree

9 files changed

+72
-72
lines changed

9 files changed

+72
-72
lines changed

lua/gitlab/actions/comment.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ M.create_comment_layout = function(opts)
207207
local settings = u.merge(popup_settings, overrides or {})
208208

209209
M.current_win = vim.api.nvim_get_current_win()
210-
M.comment_popup = Popup(u.create_popup_state(title, settings))
211-
M.draft_popup = Popup(u.create_box_popup_state("Draft", false, settings))
210+
M.comment_popup = Popup(popup.create_popup_state(title, settings))
211+
M.draft_popup = Popup(popup.create_box_popup_state("Draft", false, settings))
212212
M.start_line, M.end_line = u.get_visual_selection_boundaries()
213213

214214
local internal_layout = Layout.Box({

lua/gitlab/actions/create_mr.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,19 +330,19 @@ end
330330

331331
M.create_layout = function()
332332
local settings = u.merge(state.settings.popup, state.settings.popup.create_mr or {})
333-
local title_popup = Popup(u.create_box_popup_state("Title", false, settings))
333+
local title_popup = Popup(popup.create_box_popup_state("Title", false, settings))
334334
M.title_bufnr = title_popup.bufnr
335-
local description_popup = Popup(u.create_popup_state("Description", settings))
335+
local description_popup = Popup(popup.create_popup_state("Description", settings))
336336
M.description_bufnr = description_popup.bufnr
337-
local target_branch_popup = Popup(u.create_box_popup_state("Target branch", false, settings))
337+
local target_branch_popup = Popup(popup.create_box_popup_state("Target branch", false, settings))
338338
M.target_bufnr = target_branch_popup.bufnr
339339
local delete_title = vim.o.columns > 110 and "Delete source branch" or "Delete source"
340-
local delete_branch_popup = Popup(u.create_box_popup_state(delete_title, false, settings))
340+
local delete_branch_popup = Popup(popup.create_box_popup_state(delete_title, false, settings))
341341
M.delete_branch_bufnr = delete_branch_popup.bufnr
342342
local squash_title = vim.o.columns > 110 and "Squash commits" or "Squash"
343-
local squash_popup = Popup(u.create_box_popup_state(squash_title, false, settings))
343+
local squash_popup = Popup(popup.create_box_popup_state(squash_title, false, settings))
344344
M.squash_bufnr = squash_popup.bufnr
345-
local forked_project_id_popup = Popup(u.create_box_popup_state("Forked Project ID", false, settings))
345+
local forked_project_id_popup = Popup(popup.create_box_popup_state("Forked Project ID", false, settings))
346346
M.forked_project_id_bufnr = forked_project_id_popup.bufnr
347347

348348
local boxes = {}

lua/gitlab/actions/discussions/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ end
284284

285285
-- This function (settings.keymaps.discussion_tree.edit_comment) will open the edit popup for the current comment in the discussion tree
286286
M.edit_comment = function(tree, unlinked)
287-
local edit_popup = Popup(u.create_popup_state("Edit Comment", state.settings.popup.edit))
287+
local edit_popup = Popup(popup.create_popup_state("Edit Comment", state.settings.popup.edit))
288288
local current_node = tree:get_node()
289289
local note_node = common.get_note_node(tree, current_node)
290290
local root_node = common.get_root_node(tree, current_node)

lua/gitlab/actions/help.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ M.open = function()
2020

2121
local longest_line = u.get_longest_string(help_content_lines)
2222
local opts = { "Help", state.settings.popup.help, longest_line + 3, #help_content_lines, 70 }
23-
local help_popup = Popup(u.create_popup_state(unpack(opts)))
23+
local help_popup = Popup(popup.create_popup_state(unpack(opts)))
2424

2525
help_popup:on(event.BufLeave, function()
2626
help_popup:unmount()

lua/gitlab/actions/merge.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ local reviewer = require("gitlab.reviewer")
88
local M = {}
99

1010
local function create_squash_message_popup()
11-
return Popup(u.create_popup_state("Squash Commit Message", state.settings.popup.squash_message))
11+
return Popup(popup.create_popup_state("Squash Commit Message", state.settings.popup.squash_message))
1212
end
1313

1414
---@class MergeOpts

lua/gitlab/actions/pipeline.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ M.open = function()
4141
local height = 6 + #M.pipeline_jobs + 3
4242

4343
local pipeline_popup =
44-
Popup(u.create_popup_state("Loading Pipeline...", state.settings.popup.pipeline, width, height, 60))
44+
Popup(popup.create_popup_state("Loading Pipeline...", state.settings.popup.pipeline, width, height, 60))
4545
popup.set_up_autocommands(pipeline_popup, nil, vim.api.nvim_get_current_win())
4646
M.pipeline_popup = pipeline_popup
4747
pipeline_popup:mount()

lua/gitlab/actions/summary.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,15 @@ end
168168

169169
M.create_layout = function(info_lines)
170170
local settings = u.merge(state.settings.popup, state.settings.popup.summary or {})
171-
local title_popup = Popup(u.create_box_popup_state(nil, false, settings))
171+
local title_popup = Popup(popup.create_box_popup_state(nil, false, settings))
172172
M.title_bufnr = title_popup.bufnr
173-
local description_popup = Popup(u.create_popup_state("Description", settings))
173+
local description_popup = Popup(popup.create_popup_state("Description", settings))
174174
M.description_bufnr = description_popup.bufnr
175175
local details_popup
176176

177177
local internal_layout
178178
if state.settings.info.enabled then
179-
details_popup = Popup(u.create_box_popup_state("Details", false, settings))
179+
details_popup = Popup(popup.create_box_popup_state("Details", false, settings))
180180
if state.settings.info.horizontal then
181181
local longest_line = u.get_longest_string(info_lines)
182182
internal_layout = Layout.Box({

lua/gitlab/popup.lua

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,62 @@ local u = require("gitlab.utils")
22

33
local 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+
561
local 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

lua/gitlab/utils/init.lua

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -480,62 +480,6 @@ M.difference = function(a, b)
480480
return not_included
481481
end
482482

483-
---Get the popup view_opts
484-
---@param title string The string to appear on top of the popup
485-
---@param settings table|nil User defined popup settings
486-
---@param width number? Override default width
487-
---@param height number? Override default height
488-
---@param zindex number? Override default zindex
489-
---@return table
490-
M.create_popup_state = function(title, settings, width, height, zindex)
491-
settings = M.merge(require("gitlab.state").settings.popup, settings or {})
492-
local view_opts = {
493-
buf_options = {
494-
filetype = "markdown",
495-
},
496-
relative = "editor",
497-
enter = true,
498-
focusable = true,
499-
zindex = zindex or 50,
500-
border = {
501-
style = settings.border,
502-
text = {
503-
top = title,
504-
},
505-
},
506-
position = settings.position,
507-
size = {
508-
width = width and math.min(width, vim.o.columns - 2) or settings.width,
509-
height = height and math.min(height, vim.o.lines - 3) or settings.height,
510-
},
511-
opacity = settings.opacity,
512-
}
513-
514-
return view_opts
515-
end
516-
517-
---Create view_opts for Box popups used inside popup Layouts
518-
---@param title string|nil The string to appear on top of the popup
519-
---@param enter boolean Whether the pop should be focused after creation
520-
---@param settings table User defined popup settings
521-
---@return table
522-
M.create_box_popup_state = function(title, enter, settings)
523-
return {
524-
buf_options = {
525-
filetype = "markdown",
526-
},
527-
enter = enter or false,
528-
focusable = true,
529-
border = {
530-
style = settings.border,
531-
text = {
532-
top = title,
533-
},
534-
},
535-
opacity = settings.opacity,
536-
}
537-
end
538-
539483
M.read_file = function(file_path, opts)
540484
local file = io.open(file_path, "r")
541485
if file == nil then

0 commit comments

Comments
 (0)