feat(ui): add configurable keymaps for confirm modal (#2206)
This commit is contained in:
@@ -509,6 +509,12 @@ M._defaults = {
|
||||
},
|
||||
select_model = "<leader>a?", -- Select model command
|
||||
select_history = "<leader>ah", -- Select history command
|
||||
confirm = {
|
||||
focus_window = "<C-w>f",
|
||||
code = "c",
|
||||
resp = "r",
|
||||
input = "i",
|
||||
},
|
||||
},
|
||||
windows = {
|
||||
---@alias AvantePosition "right" | "left" | "top" | "bottom" | "smart"
|
||||
|
||||
@@ -46,18 +46,17 @@ function M:open()
|
||||
|
||||
local commentfg = Highlights.AVANTE_COMMENT_FG
|
||||
|
||||
-- local keybindings_content = "<C-w>f: focus; c: code; r: resp; i: input"
|
||||
local keybindings_line = Line:new({
|
||||
{ " <C-w>f ", "visual" },
|
||||
{ " " .. Config.mappings.confirm.focus_window .. " ", "visual" },
|
||||
{ " - focus ", commentfg },
|
||||
{ " " },
|
||||
{ " c ", "visual" },
|
||||
{ " " .. Config.mappings.confirm.code .. " ", "visual" },
|
||||
{ " - code ", commentfg },
|
||||
{ " " },
|
||||
{ " r ", "visual" },
|
||||
{ " " .. Config.mappings.confirm.resp .. " ", "visual" },
|
||||
{ " - resp ", commentfg },
|
||||
{ " " },
|
||||
{ " i ", "visual" },
|
||||
{ " " .. Config.mappings.confirm.input .. " ", "visual" },
|
||||
{ " - input ", commentfg },
|
||||
{ " " },
|
||||
})
|
||||
@@ -176,7 +175,7 @@ function M:open()
|
||||
prompt_input:open()
|
||||
end
|
||||
|
||||
vim.keymap.set("n", "c", function()
|
||||
vim.keymap.set("n", Config.mappings.confirm.code, function()
|
||||
local sidebar = require("avante").get()
|
||||
if not sidebar then return end
|
||||
if sidebar.code.winid and vim.api.nvim_win_is_valid(sidebar.code.winid) then
|
||||
@@ -184,7 +183,7 @@ function M:open()
|
||||
end
|
||||
end, { buffer = popup.bufnr })
|
||||
|
||||
vim.keymap.set("n", "r", function()
|
||||
vim.keymap.set("n", Config.mappings.confirm.resp, function()
|
||||
local sidebar = require("avante").get()
|
||||
if not sidebar then return end
|
||||
if sidebar.winids.result_container and vim.api.nvim_win_is_valid(sidebar.winids.result_container) then
|
||||
@@ -192,7 +191,7 @@ function M:open()
|
||||
end
|
||||
end, { buffer = popup.bufnr })
|
||||
|
||||
vim.keymap.set("n", "i", function()
|
||||
vim.keymap.set("n", Config.mappings.confirm.input, function()
|
||||
local sidebar = require("avante").get()
|
||||
if not sidebar then return end
|
||||
if sidebar.winids.input_container and vim.api.nvim_win_is_valid(sidebar.winids.input_container) then
|
||||
@@ -340,10 +339,10 @@ function M:window_focus_handler()
|
||||
end
|
||||
|
||||
function M:bind_window_focus_keymaps()
|
||||
vim.keymap.set({ "n", "i" }, "<C-w>f", function() self:window_focus_handler() end)
|
||||
vim.keymap.set({ "n", "i" }, Config.mappings.confirm.focus_window, function() self:window_focus_handler() end)
|
||||
end
|
||||
|
||||
function M:unbind_window_focus_keymaps() pcall(vim.keymap.del, { "n", "i" }, "<C-w>f") end
|
||||
function M:unbind_window_focus_keymaps() pcall(vim.keymap.del, { "n", "i" }, Config.mappings.confirm.focus_window) end
|
||||
|
||||
function M:cancel()
|
||||
self.callback("no", "cancel")
|
||||
|
||||
Reference in New Issue
Block a user