From c8c7d86e84fceace885c276df876503aacc642cb Mon Sep 17 00:00:00 2001 From: Harrison Cramer Date: Fri, 8 Sep 2023 20:45:28 -0400 Subject: [PATCH] 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. --- lua/gitlab/actions/summary.lua | 5 +++-- lua/gitlab/state.lua | 14 ++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lua/gitlab/actions/summary.lua b/lua/gitlab/actions/summary.lua index 86dd124..a73ed9f 100644 --- a/lua/gitlab/actions/summary.lua +++ b/lua/gitlab/actions/summary.lua @@ -48,8 +48,9 @@ M.summary = function() vim.schedule(function() vim.api.nvim_buf_set_lines(currentBuffer, 0, -1, false, lines) vim.api.nvim_buf_set_lines(title_popup.bufnr, 0, -1, false, { title }) - state.set_popup_keymaps(description_popup, M.edit_summary, miscellaneous.attach_file, exit) - state.set_popup_keymaps(title_popup, M.edit_summary, nil, exit) + state.set_popup_keymaps(description_popup, M.edit_summary, miscellaneous.attach_file, + { cb = exit, action_before_close = true }) + state.set_popup_keymaps(title_popup, M.edit_summary, nil, { cb = exit, action_before_close = true }) end) end diff --git a/lua/gitlab/state.lua b/lua/gitlab/state.lua index 0b11553..57432f8 100644 --- a/lua/gitlab/state.lua +++ b/lua/gitlab/state.lua @@ -113,13 +113,19 @@ local function exit(popup, cb) end -- These keymaps are buffer specific and are set dynamically when popups mount -M.set_popup_keymaps = function(popup, action, linewise_action, cb) - vim.keymap.set('n', M.settings.popup.exit, function() exit(popup, cb) end, { buffer = popup.bufnr }) +M.set_popup_keymaps = function(popup, action, linewise_action, opts) + if opts == nil then opts = {} end + vim.keymap.set('n', M.settings.popup.exit, function() exit(popup, opts.cb) end, { buffer = popup.bufnr }) if action ~= nil then vim.keymap.set('n', M.settings.popup.perform_action, function() local text = u.get_buffer_text(popup.bufnr) - action(text) - exit(popup) + if opts.action_before_close then + action(text, popup.bufnr) + exit(popup) + else + exit(popup) + action(text, popup.bufnr) + end end, { buffer = popup.bufnr }) end