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:
@@ -48,8 +48,9 @@ M.summary = function()
|
|||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
vim.api.nvim_buf_set_lines(currentBuffer, 0, -1, false, lines)
|
vim.api.nvim_buf_set_lines(currentBuffer, 0, -1, false, lines)
|
||||||
vim.api.nvim_buf_set_lines(title_popup.bufnr, 0, -1, false, { title })
|
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(description_popup, M.edit_summary, miscellaneous.attach_file,
|
||||||
state.set_popup_keymaps(title_popup, M.edit_summary, nil, exit)
|
{ cb = exit, action_before_close = true })
|
||||||
|
state.set_popup_keymaps(title_popup, M.edit_summary, nil, { cb = exit, action_before_close = true })
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -113,13 +113,19 @@ local function exit(popup, cb)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- These keymaps are buffer specific and are set dynamically when popups mount
|
-- These keymaps are buffer specific and are set dynamically when popups mount
|
||||||
M.set_popup_keymaps = function(popup, action, linewise_action, cb)
|
M.set_popup_keymaps = function(popup, action, linewise_action, opts)
|
||||||
vim.keymap.set('n', M.settings.popup.exit, function() exit(popup, cb) end, { buffer = popup.bufnr })
|
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
|
if action ~= nil then
|
||||||
vim.keymap.set('n', M.settings.popup.perform_action, function()
|
vim.keymap.set('n', M.settings.popup.perform_action, function()
|
||||||
local text = u.get_buffer_text(popup.bufnr)
|
local text = u.get_buffer_text(popup.bufnr)
|
||||||
action(text)
|
if opts.action_before_close then
|
||||||
|
action(text, popup.bufnr)
|
||||||
exit(popup)
|
exit(popup)
|
||||||
|
else
|
||||||
|
exit(popup)
|
||||||
|
action(text, popup.bufnr)
|
||||||
|
end
|
||||||
end, { buffer = popup.bufnr })
|
end, { buffer = popup.bufnr })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user