diff --git a/lua/gp/helper.lua b/lua/gp/helper.lua index 8612429a..d82da999 100644 --- a/lua/gp/helper.lua +++ b/lua/gp/helper.lua @@ -20,6 +20,17 @@ end ---@param callback function | string # callback or string to set keymap ---@param desc string | nil # optional description for keymap _H.set_keymap = function(buffers, mode, key, callback, desc) + logger.debug( + "registering shortcut:" + .. " mode: " + .. vim.inspect(mode) + .. " key: " + .. key + .. " buffers: " + .. vim.inspect(buffers) + .. " callback: " + .. vim.inspect(callback) + ) for _, buf in ipairs(buffers) do vim.keymap.set(mode, key, callback, { noremap = true, @@ -64,6 +75,7 @@ end ---@param file string | nil # name of the file to delete _H.delete_file = function(file) + logger.debug("deleting file: " .. vim.inspect(file)) if file == nil then return end diff --git a/lua/gp/init.lua b/lua/gp/init.lua index bcd36282..b1efc87c 100644 --- a/lua/gp/init.lua +++ b/lua/gp/init.lua @@ -1158,7 +1158,7 @@ M.cmd.ChatFinder = function() local right = M.config.style_chat_finder_margin_right or 2 local picker_buf, picker_win, picker_close, picker_resize = M.render.popup( nil, - "Picker: j/k |exit |open dd|del i|srch", + "Picker: j/k |exit |open " .. M.config.chat_shortcut_delete.shortcut .. "|del i|srch", function(w, h) local wh = h - top - bottom - 2 local ww = w - left - right - 2 @@ -1185,7 +1185,7 @@ M.cmd.ChatFinder = function() local command_buf, command_win, command_close, command_resize = M.render.popup( nil, "Search: /|navigate |picker |exit " - .. "/////|open/float/split/vsplit/tab/toggle", + .. "/////t|open/float/split/vsplit/tab/toggle", function(w, h) return w - left - right, 1, h - bottom, left end, @@ -1380,7 +1380,7 @@ M.cmd.ChatFinder = function() M.helpers.set_keymap({ picker_buf, preview_buf, command_buf }, { "i", "n", "v" }, "", function() open_chat(M.BufTarget.tabnew, false) end) - M.helpers.set_keymap({ picker_buf, preview_buf, command_buf }, { "i", "n", "v" }, "", function() + M.helpers.set_keymap({ picker_buf, preview_buf, command_buf }, { "i", "n", "v" }, "t", function() local target = M.resolve_buf_target(M.config.toggle_target) open_chat(target, true) end) @@ -1408,25 +1408,30 @@ M.cmd.ChatFinder = function() end) -- dd on picker or preview window will delete file - M.helpers.set_keymap({ picker_buf, preview_buf }, "n", "dd", function() - local index = vim.api.nvim_win_get_cursor(picker_win)[1] - local file = picker_files[index] - - -- delete without confirmation - if not M.config.chat_confirm_delete then - M.helpers.delete_file(file) - refresh_picker() - return - end - - -- ask for confirmation - vim.ui.input({ prompt = "Delete " .. file .. "? [y/N] " }, function(input) - if input and input:lower() == "y" then + M.helpers.set_keymap( + { command_buf, picker_buf, preview_buf }, + { "i", "n", "v" }, + M.config.chat_shortcut_delete.shortcut, + function() + local index = vim.api.nvim_win_get_cursor(picker_win)[1] + local file = picker_files[index] + + -- delete without confirmation + if not M.config.chat_confirm_delete then M.helpers.delete_file(file) refresh_picker() + return end - end) - end) + + -- ask for confirmation + vim.ui.input({ prompt = "Delete " .. file .. "? [y/N] " }, function(input) + if input and input:lower() == "y" then + M.helpers.delete_file(file) + refresh_picker() + end + end) + end + ) end --------------------------------------------------------------------------------