Add user option for sidebar window focus mapping ()

* add mappings for window navigation in sidebar

* add new mapping option to readme

* rollback formatitng changes in Readme file
This commit is contained in:
Valentin Berlin 2024-09-14 20:42:55 +02:00 committed by GitHub
parent 932535aa99
commit cea3dfb85b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 6 deletions

@ -231,6 +231,10 @@ _See [config.lua#L9](./lua/avante/config.lua) for the full config_
normal = "<CR>", normal = "<CR>",
insert = "<C-s>", insert = "<C-s>",
}, },
sidebar = {
switch_windows = "<Tab>",
reverse_switch_windows = "<S-Tab>",
},
}, },
hints = { enabled = true }, hints = { enabled = true },
windows = { windows = {

@ -148,6 +148,10 @@ You are an excellent programming expert.
hint = "<leader>ah", hint = "<leader>ah",
suggestion = "<leader>as", suggestion = "<leader>as",
}, },
sidebar = {
switch_windows = "<Tab>",
reverse_switch_windows = "<S-Tab>",
},
}, },
windows = { windows = {
---@alias AvantePosition "right" | "left" | "top" | "bottom" ---@alias AvantePosition "right" | "left" | "top" | "bottom"

@ -616,8 +616,12 @@ function Sidebar:render_input(ask)
local code_file_fullpath = api.nvim_buf_get_name(self.code.bufnr) local code_file_fullpath = api.nvim_buf_get_name(self.code.bufnr)
local code_filename = fn.fnamemodify(code_file_fullpath, ":t") local code_filename = fn.fnamemodify(code_file_fullpath, ":t")
local header_text = local header_text = string.format(
string.format("󱜸 %s %s %s (<Tab>: switch focus)", ask and "Ask" or "Chat with", icon, code_filename) "󱜸 %s %s %s (" .. Config.mappings.sidebar.switch_windows .. ": switch focus)",
ask and "Ask" or "Chat with",
icon,
code_filename
)
if self.code.selection ~= nil then if self.code.selection ~= nil then
header_text = string.format( header_text = string.format(
@ -887,15 +891,15 @@ function Sidebar:refresh_winids()
for _, winid in ipairs(winids) do for _, winid in ipairs(winids) do
local buf = api.nvim_win_get_buf(winid) local buf = api.nvim_win_get_buf(winid)
vim.keymap.set( Utils.safe_keymap_set(
{ "n", "i" }, { "n", "i" },
"<Tab>", Config.mappings.sidebar.switch_windows,
function() switch_windows() end, function() switch_windows() end,
{ buffer = buf, noremap = true, silent = true } { buffer = buf, noremap = true, silent = true }
) )
vim.keymap.set( Utils.safe_keymap_set(
{ "n", "i" }, { "n", "i" },
"<S-Tab>", Config.mappings.sidebar.reverse_switch_windows,
function() reverse_switch_windows() end, function() reverse_switch_windows() end,
{ buffer = buf, noremap = true, silent = true } { buffer = buf, noremap = true, silent = true }
) )