Skip to content

Commit 919fdd4

Browse files
committed
feat: reuse chat_confirm_delete shortcut in chat picker
1 parent 5ebccef commit 919fdd4

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

lua/gp/helper.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ end
2020
---@param callback function | string # callback or string to set keymap
2121
---@param desc string | nil # optional description for keymap
2222
_H.set_keymap = function(buffers, mode, key, callback, desc)
23+
logger.debug(
24+
"registering shortcut:"
25+
.. " mode: "
26+
.. vim.inspect(mode)
27+
.. " key: "
28+
.. key
29+
.. " buffers: "
30+
.. vim.inspect(buffers)
31+
.. " callback: "
32+
.. vim.inspect(callback)
33+
)
2334
for _, buf in ipairs(buffers) do
2435
vim.keymap.set(mode, key, callback, {
2536
noremap = true,
@@ -64,6 +75,7 @@ end
6475

6576
---@param file string | nil # name of the file to delete
6677
_H.delete_file = function(file)
78+
logger.debug("deleting file: " .. vim.inspect(file))
6779
if file == nil then
6880
return
6981
end

lua/gp/init.lua

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ M.cmd.ChatFinder = function()
11581158
local right = M.config.style_chat_finder_margin_right or 2
11591159
local picker_buf, picker_win, picker_close, picker_resize = M.render.popup(
11601160
nil,
1161-
"Picker: j/k <Esc>|exit <Enter>|open dd|del i|srch",
1161+
"Picker: j/k <Esc>|exit <Enter>|open " .. M.config.chat_shortcut_delete.shortcut .. "|del i|srch",
11621162
function(w, h)
11631163
local wh = h - top - bottom - 2
11641164
local ww = w - left - right - 2
@@ -1185,7 +1185,7 @@ M.cmd.ChatFinder = function()
11851185
local command_buf, command_win, command_close, command_resize = M.render.popup(
11861186
nil,
11871187
"Search: <Tab>/<Shift+Tab>|navigate <Esc>|picker <C-c>|exit "
1188-
.. "<Enter>/<C-f>/<C-x>/<C-v>/<C-t>/<C-g>|open/float/split/vsplit/tab/toggle",
1188+
.. "<Enter>/<C-f>/<C-x>/<C-v>/<C-t>/<C-g>t|open/float/split/vsplit/tab/toggle",
11891189
function(w, h)
11901190
return w - left - right, 1, h - bottom, left
11911191
end,
@@ -1380,7 +1380,7 @@ M.cmd.ChatFinder = function()
13801380
M.helpers.set_keymap({ picker_buf, preview_buf, command_buf }, { "i", "n", "v" }, "<C-t>", function()
13811381
open_chat(M.BufTarget.tabnew, false)
13821382
end)
1383-
M.helpers.set_keymap({ picker_buf, preview_buf, command_buf }, { "i", "n", "v" }, "<C-g>", function()
1383+
M.helpers.set_keymap({ picker_buf, preview_buf, command_buf }, { "i", "n", "v" }, "<C-g>t", function()
13841384
local target = M.resolve_buf_target(M.config.toggle_target)
13851385
open_chat(target, true)
13861386
end)
@@ -1408,25 +1408,30 @@ M.cmd.ChatFinder = function()
14081408
end)
14091409

14101410
-- dd on picker or preview window will delete file
1411-
M.helpers.set_keymap({ picker_buf, preview_buf }, "n", "dd", function()
1412-
local index = vim.api.nvim_win_get_cursor(picker_win)[1]
1413-
local file = picker_files[index]
1414-
1415-
-- delete without confirmation
1416-
if not M.config.chat_confirm_delete then
1417-
M.helpers.delete_file(file)
1418-
refresh_picker()
1419-
return
1420-
end
1421-
1422-
-- ask for confirmation
1423-
vim.ui.input({ prompt = "Delete " .. file .. "? [y/N] " }, function(input)
1424-
if input and input:lower() == "y" then
1411+
M.helpers.set_keymap(
1412+
{ command_buf, picker_buf, preview_buf },
1413+
{ "i", "n", "v" },
1414+
M.config.chat_shortcut_delete.shortcut,
1415+
function()
1416+
local index = vim.api.nvim_win_get_cursor(picker_win)[1]
1417+
local file = picker_files[index]
1418+
1419+
-- delete without confirmation
1420+
if not M.config.chat_confirm_delete then
14251421
M.helpers.delete_file(file)
14261422
refresh_picker()
1423+
return
14271424
end
1428-
end)
1429-
end)
1425+
1426+
-- ask for confirmation
1427+
vim.ui.input({ prompt = "Delete " .. file .. "? [y/N] " }, function(input)
1428+
if input and input:lower() == "y" then
1429+
M.helpers.delete_file(file)
1430+
refresh_picker()
1431+
end
1432+
end)
1433+
end
1434+
)
14301435
end
14311436

14321437
--------------------------------------------------------------------------------

0 commit comments

Comments
 (0)