feat(ui): add configurable keymaps for confirm modal (#2206)

This commit is contained in:
Brewinski
2025-06-12 13:26:58 +10:00
committed by GitHub
parent 2030512dfe
commit 2675155a76
2 changed files with 15 additions and 10 deletions

View File

@@ -509,6 +509,12 @@ M._defaults = {
}, },
select_model = "<leader>a?", -- Select model command select_model = "<leader>a?", -- Select model command
select_history = "<leader>ah", -- Select history command select_history = "<leader>ah", -- Select history command
confirm = {
focus_window = "<C-w>f",
code = "c",
resp = "r",
input = "i",
},
}, },
windows = { windows = {
---@alias AvantePosition "right" | "left" | "top" | "bottom" | "smart" ---@alias AvantePosition "right" | "left" | "top" | "bottom" | "smart"

View File

@@ -46,18 +46,17 @@ function M:open()
local commentfg = Highlights.AVANTE_COMMENT_FG local commentfg = Highlights.AVANTE_COMMENT_FG
-- local keybindings_content = "<C-w>f: focus; c: code; r: resp; i: input"
local keybindings_line = Line:new({ local keybindings_line = Line:new({
{ " <C-w>f ", "visual" }, { " " .. Config.mappings.confirm.focus_window .. " ", "visual" },
{ " - focus ", commentfg }, { " - focus ", commentfg },
{ " " }, { " " },
{ " c ", "visual" }, { " " .. Config.mappings.confirm.code .. " ", "visual" },
{ " - code ", commentfg }, { " - code ", commentfg },
{ " " }, { " " },
{ " r ", "visual" }, { " " .. Config.mappings.confirm.resp .. " ", "visual" },
{ " - resp ", commentfg }, { " - resp ", commentfg },
{ " " }, { " " },
{ " i ", "visual" }, { " " .. Config.mappings.confirm.input .. " ", "visual" },
{ " - input ", commentfg }, { " - input ", commentfg },
{ " " }, { " " },
}) })
@@ -176,7 +175,7 @@ function M:open()
prompt_input:open() prompt_input:open()
end end
vim.keymap.set("n", "c", function() vim.keymap.set("n", Config.mappings.confirm.code, function()
local sidebar = require("avante").get() local sidebar = require("avante").get()
if not sidebar then return end if not sidebar then return end
if sidebar.code.winid and vim.api.nvim_win_is_valid(sidebar.code.winid) then if sidebar.code.winid and vim.api.nvim_win_is_valid(sidebar.code.winid) then
@@ -184,7 +183,7 @@ function M:open()
end end
end, { buffer = popup.bufnr }) end, { buffer = popup.bufnr })
vim.keymap.set("n", "r", function() vim.keymap.set("n", Config.mappings.confirm.resp, function()
local sidebar = require("avante").get() local sidebar = require("avante").get()
if not sidebar then return end if not sidebar then return end
if sidebar.winids.result_container and vim.api.nvim_win_is_valid(sidebar.winids.result_container) then 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
end, { buffer = popup.bufnr }) end, { buffer = popup.bufnr })
vim.keymap.set("n", "i", function() vim.keymap.set("n", Config.mappings.confirm.input, function()
local sidebar = require("avante").get() local sidebar = require("avante").get()
if not sidebar then return end if not sidebar then return end
if sidebar.winids.input_container and vim.api.nvim_win_is_valid(sidebar.winids.input_container) then 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 end
function M:bind_window_focus_keymaps() 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 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() function M:cancel()
self.callback("no", "cancel") self.callback("no", "cancel")