Skip to content

Commit c8c7d86

Browse files
Bugfix: We must allow most actions to occur after the popup closes.
Some (like editing the title and description) need the popup text and should execute prior to closure. This is now configurable via an options table that can be passed to the set_popup_keymaps function.
1 parent f6fb616 commit c8c7d86

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

lua/gitlab/actions/summary.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ M.summary = function()
4848
vim.schedule(function()
4949
vim.api.nvim_buf_set_lines(currentBuffer, 0, -1, false, lines)
5050
vim.api.nvim_buf_set_lines(title_popup.bufnr, 0, -1, false, { title })
51-
state.set_popup_keymaps(description_popup, M.edit_summary, miscellaneous.attach_file, exit)
52-
state.set_popup_keymaps(title_popup, M.edit_summary, nil, exit)
51+
state.set_popup_keymaps(description_popup, M.edit_summary, miscellaneous.attach_file,
52+
{ cb = exit, action_before_close = true })
53+
state.set_popup_keymaps(title_popup, M.edit_summary, nil, { cb = exit, action_before_close = true })
5354
end)
5455
end
5556

lua/gitlab/state.lua

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,19 @@ local function exit(popup, cb)
113113
end
114114

115115
-- These keymaps are buffer specific and are set dynamically when popups mount
116-
M.set_popup_keymaps = function(popup, action, linewise_action, cb)
117-
vim.keymap.set('n', M.settings.popup.exit, function() exit(popup, cb) end, { buffer = popup.bufnr })
116+
M.set_popup_keymaps = function(popup, action, linewise_action, opts)
117+
if opts == nil then opts = {} end
118+
vim.keymap.set('n', M.settings.popup.exit, function() exit(popup, opts.cb) end, { buffer = popup.bufnr })
118119
if action ~= nil then
119120
vim.keymap.set('n', M.settings.popup.perform_action, function()
120121
local text = u.get_buffer_text(popup.bufnr)
121-
action(text)
122-
exit(popup)
122+
if opts.action_before_close then
123+
action(text, popup.bufnr)
124+
exit(popup)
125+
else
126+
exit(popup)
127+
action(text, popup.bufnr)
128+
end
123129
end, { buffer = popup.bufnr })
124130
end
125131

0 commit comments

Comments
 (0)