Add option custom_init to enable user to customize behaviour of sidebar (#2630)
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
This commit is contained in:
@@ -110,6 +110,8 @@ end
|
|||||||
---@field floating? boolean whether to open a floating input to enter the question
|
---@field floating? boolean whether to open a floating input to enter the question
|
||||||
---@field new_chat? boolean whether to open a new chat
|
---@field new_chat? boolean whether to open a new chat
|
||||||
---@field without_selection? boolean whether to open a new chat without selection
|
---@field without_selection? boolean whether to open a new chat without selection
|
||||||
|
---@field sidebar_pre_render? fun(sidebar: avante.Sidebar)
|
||||||
|
---@field sidebar_post_render? fun(sidebar: avante.Sidebar)
|
||||||
|
|
||||||
---@param opts? AskOptions
|
---@param opts? AskOptions
|
||||||
function M.ask(opts)
|
function M.ask(opts)
|
||||||
|
|||||||
@@ -524,6 +524,7 @@ M._defaults = {
|
|||||||
-- NOTE: The following will be safely set by avante.nvim
|
-- NOTE: The following will be safely set by avante.nvim
|
||||||
ask = "<leader>aa",
|
ask = "<leader>aa",
|
||||||
new_ask = "<leader>an",
|
new_ask = "<leader>an",
|
||||||
|
full_view_ask = "<leader>am",
|
||||||
edit = "<leader>ae",
|
edit = "<leader>ae",
|
||||||
refresh = "<leader>ar",
|
refresh = "<leader>ar",
|
||||||
focus = "<leader>af",
|
focus = "<leader>af",
|
||||||
|
|||||||
@@ -94,6 +94,15 @@ function H.keymaps()
|
|||||||
function() require("avante.api").ask() end,
|
function() require("avante.api").ask() end,
|
||||||
{ desc = "avante: ask" }
|
{ desc = "avante: ask" }
|
||||||
)
|
)
|
||||||
|
Utils.safe_keymap_set({ "n", "v" }, Config.mappings.full_view_ask, function()
|
||||||
|
require("avante.api").ask({
|
||||||
|
sidebar_post_render = function(sidebar)
|
||||||
|
sidebar:toggle_code_window()
|
||||||
|
vim.wo[sidebar.containers.result.winid].number = true
|
||||||
|
vim.wo[sidebar.containers.result.winid].relativenumber = true
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end, { desc = "avante: ask with full result view" })
|
||||||
Utils.safe_keymap_set(
|
Utils.safe_keymap_set(
|
||||||
{ "n", "v" },
|
{ "n", "v" },
|
||||||
Config.mappings.new_ask,
|
Config.mappings.new_ask,
|
||||||
|
|||||||
@@ -1479,7 +1479,7 @@ function Sidebar:resize()
|
|||||||
vim.defer_fn(function() vim.cmd("AvanteRefresh") end, 200)
|
vim.defer_fn(function() vim.cmd("AvanteRefresh") end, 200)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Sidebar:toggleCodeWindow()
|
function Sidebar:toggle_code_window()
|
||||||
local win_width = api.nvim_win_get_width(self.code.winid)
|
local win_width = api.nvim_win_get_width(self.code.winid)
|
||||||
if win_width == 0 then
|
if win_width == 0 then
|
||||||
api.nvim_win_set_width(self.code.winid, self.code.win_width)
|
api.nvim_win_set_width(self.code.winid, self.code.win_width)
|
||||||
@@ -2734,14 +2734,14 @@ function Sidebar:create_input_container()
|
|||||||
self.containers.input:map(
|
self.containers.input:map(
|
||||||
"n",
|
"n",
|
||||||
Config.mappings.sidebar.toggle_code_window_from_input.normal,
|
Config.mappings.sidebar.toggle_code_window_from_input.normal,
|
||||||
function() self:toggleCodeWindow() end
|
function() self:toggle_code_window() end
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
if Config.mappings.sidebar.toggle_code_window_from_input.insert ~= nil then
|
if Config.mappings.sidebar.toggle_code_window_from_input.insert ~= nil then
|
||||||
self.containers.input:map(
|
self.containers.input:map(
|
||||||
"i",
|
"i",
|
||||||
Config.mappings.sidebar.toggle_code_window_from_input.insert,
|
Config.mappings.sidebar.toggle_code_window_from_input.insert,
|
||||||
function() self:toggleCodeWindow() end
|
function() self:toggle_code_window() end
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -2892,6 +2892,7 @@ end
|
|||||||
---@param opts AskOptions
|
---@param opts AskOptions
|
||||||
function Sidebar:render(opts)
|
function Sidebar:render(opts)
|
||||||
self.ask_opts = opts
|
self.ask_opts = opts
|
||||||
|
if opts.sidebar_pre_render then opts.sidebar_pre_render(self) end
|
||||||
|
|
||||||
local function get_position()
|
local function get_position()
|
||||||
return (opts and opts.win and opts.win.position) and opts.win.position or calculate_config_window_position()
|
return (opts and opts.win and opts.win.position) and opts.win.position or calculate_config_window_position()
|
||||||
@@ -2928,7 +2929,7 @@ function Sidebar:render(opts)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
self.containers.result:map("n", Config.mappings.sidebar.close, function() self:shutdown() end)
|
self.containers.result:map("n", Config.mappings.sidebar.close, function() self:shutdown() end)
|
||||||
self.containers.result:map("n", Config.mappings.sidebar.toggle_code_window, function() self:toggleCodeWindow() end)
|
self.containers.result:map("n", Config.mappings.sidebar.toggle_code_window, function() self:toggle_code_window() end)
|
||||||
|
|
||||||
self:create_input_container()
|
self:create_input_container()
|
||||||
|
|
||||||
@@ -2958,6 +2959,7 @@ function Sidebar:render(opts)
|
|||||||
|
|
||||||
self:setup_colors()
|
self:setup_colors()
|
||||||
|
|
||||||
|
if opts.sidebar_post_render then vim.defer_fn(function() opts.sidebar_post_render(self) end, 100) end
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user