feat(sidebar): Add option and keymap to start a new chat directly (#2004)

This commit is contained in:
aniaan
2025-05-07 15:27:50 +08:00
committed by GitHub
parent 103b827b60
commit 113913355a
3 changed files with 16 additions and 2 deletions

View File

@@ -111,8 +111,9 @@ function M.ask(opts)
end
local has_question = opts.question ~= nil and opts.question ~= ""
local new_chat = opts.new_chat == true
if Utils.is_sidebar_buffer(0) and not has_question then
if Utils.is_sidebar_buffer(0) and not has_question and not new_chat then
require("avante").close_sidebar()
return false
end
@@ -127,7 +128,7 @@ function M.ask(opts)
sidebar:close({ goto_code_win = false })
end
require("avante").open_sidebar(opts)
if opts.new_chat then sidebar:new_chat() end
if new_chat then sidebar:new_chat() end
if opts.without_selection then
sidebar.code.selection = nil
sidebar.file_selector:reset()

View File

@@ -435,6 +435,7 @@ M._defaults = {
},
-- NOTE: The following will be safely set by avante.nvim
ask = "<leader>aa",
new_ask = "<leader>an",
edit = "<leader>ae",
refresh = "<leader>ar",
focus = "<leader>af",

View File

@@ -57,6 +57,12 @@ end
function H.keymaps()
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteAsk)", function() require("avante.api").ask() end, { noremap = true })
vim.keymap.set(
{ "n", "v" },
"<Plug>(AvanteAskNew)",
function() require("avante.api").ask({ new_chat = true }) end,
{ noremap = true }
)
vim.keymap.set(
{ "n", "v" },
"<Plug>(AvanteChat)",
@@ -88,6 +94,12 @@ function H.keymaps()
function() require("avante.api").ask() end,
{ desc = "avante: ask" }
)
Utils.safe_keymap_set(
{ "n", "v" },
Config.mappings.new_ask,
function() require("avante.api").ask({ new_chat = true }) end,
{ desc = "avante: create new ask" }
)
Utils.safe_keymap_set(
"v",
Config.mappings.edit,