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.
This commit is contained in:
Harrison Cramer
2023-09-08 20:45:28 -04:00
parent f6fb61607c
commit c8c7d86e84
2 changed files with 13 additions and 6 deletions

View File

@@ -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

View File

@@ -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)
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