feat(api): add switch sidebar focus (#709)
This commit is contained in:
@@ -175,6 +175,32 @@ M.refresh = function(opts)
|
||||
sidebar:render(opts)
|
||||
end
|
||||
|
||||
---@param opts? AskOptions
|
||||
M.focus = function(opts)
|
||||
opts = opts or {}
|
||||
local sidebar = require("avante").get()
|
||||
if not sidebar then return end
|
||||
|
||||
local curbuf = vim.api.nvim_get_current_buf()
|
||||
local curwin = vim.api.nvim_get_current_win()
|
||||
|
||||
if sidebar:is_open() then
|
||||
if curbuf == sidebar.input.bufnr then
|
||||
if sidebar.code.winid and sidebar.code.winid ~= curwin then vim.api.nvim_set_current_win(sidebar.code.winid) end
|
||||
elseif curbuf == sidebar.result.bufnr then
|
||||
if sidebar.code.winid and sidebar.code.winid ~= curwin then vim.api.nvim_set_current_win(sidebar.code.winid) end
|
||||
else
|
||||
if sidebar.input.winid and sidebar.input.winid ~= curwin then
|
||||
vim.api.nvim_set_current_win(sidebar.input.winid)
|
||||
end
|
||||
end
|
||||
else
|
||||
if sidebar.code.winid then vim.api.nvim_set_current_win(sidebar.code.winid) end
|
||||
sidebar:open(opts)
|
||||
if sidebar.input.winid then vim.api.nvim_set_current_win(sidebar.input.winid) end
|
||||
end
|
||||
end
|
||||
|
||||
return setmetatable(M, {
|
||||
__index = function(t, k)
|
||||
local module = require("avante")
|
||||
|
||||
@@ -144,6 +144,7 @@ Respect and use existing conventions, libraries, etc that are already present in
|
||||
ask = "<leader>aa",
|
||||
edit = "<leader>ae",
|
||||
refresh = "<leader>ar",
|
||||
focus = "<leader>af",
|
||||
toggle = {
|
||||
default = "<leader>at",
|
||||
debug = "<leader>ad",
|
||||
|
||||
@@ -77,6 +77,7 @@ H.commands = function()
|
||||
{ desc = "avante: edit selected block", nargs = "*" }
|
||||
)
|
||||
cmd("Refresh", function() require("avante.api").refresh() end, { desc = "avante: refresh windows" })
|
||||
cmd("Focus", function() require("avante.api").focus() end, { desc = "avante: switch focus windows" })
|
||||
cmd("Build", function(opts)
|
||||
local args = {}
|
||||
for _, arg in ipairs(opts.fargs) do
|
||||
@@ -113,6 +114,7 @@ H.keymaps = function()
|
||||
)
|
||||
vim.keymap.set("v", "<Plug>(AvanteEdit)", function() require("avante.api").edit() end, { noremap = true })
|
||||
vim.keymap.set("n", "<Plug>(AvanteRefresh)", function() require("avante.api").refresh() end, { noremap = true })
|
||||
vim.keymap.set("n", "<Plug>(AvanteFocus)", function() require("avante.api").focus() end, { noremap = true })
|
||||
vim.keymap.set("n", "<Plug>(AvanteBuild)", function() require("avante.api").build() end, { noremap = true })
|
||||
vim.keymap.set("n", "<Plug>(AvanteToggle)", function() M.toggle() end, { noremap = true })
|
||||
vim.keymap.set("n", "<Plug>(AvanteToggleDebug)", function() M.toggle.debug() end)
|
||||
@@ -146,6 +148,13 @@ H.keymaps = function()
|
||||
function() require("avante.api").refresh() end,
|
||||
{ desc = "avante: refresh" }
|
||||
)
|
||||
Utils.safe_keymap_set(
|
||||
"n",
|
||||
Config.mappings.focus,
|
||||
function() require("avante.api").focus() end,
|
||||
{ desc = "avante: focus" }
|
||||
)
|
||||
|
||||
Utils.safe_keymap_set("n", Config.mappings.toggle.default, function() M.toggle() end, { desc = "avante: toggle" })
|
||||
Utils.safe_keymap_set(
|
||||
"n",
|
||||
|
||||
Reference in New Issue
Block a user