feat: add horizontal layout
This commit is contained in:
parent
c324e902bb
commit
ff887af901
@ -18,6 +18,8 @@ M.defaults = {
|
|||||||
-- For most providers that we support we will determine this automatically.
|
-- For most providers that we support we will determine this automatically.
|
||||||
-- If you wish to use a given implementation, then you can override it here.
|
-- If you wish to use a given implementation, then you can override it here.
|
||||||
tokenizer = "tiktoken",
|
tokenizer = "tiktoken",
|
||||||
|
---@type "vertical" | "horizontal"
|
||||||
|
layout = "vertical",
|
||||||
---@type AvanteSupportedProvider
|
---@type AvanteSupportedProvider
|
||||||
openai = {
|
openai = {
|
||||||
endpoint = "https://api.openai.com/v1",
|
endpoint = "https://api.openai.com/v1",
|
||||||
@ -137,6 +139,7 @@ M.defaults = {
|
|||||||
windows = {
|
windows = {
|
||||||
wrap = true, -- similar to vim.o.wrap
|
wrap = true, -- similar to vim.o.wrap
|
||||||
width = 30, -- default % based on available width
|
width = 30, -- default % based on available width
|
||||||
|
height = 30, -- default % based on available height
|
||||||
sidebar_header = {
|
sidebar_header = {
|
||||||
align = "center", -- left, center, right for title
|
align = "center", -- left, center, right for title
|
||||||
rounded = true,
|
rounded = true,
|
||||||
|
@ -1374,6 +1374,26 @@ function Sidebar:create_input()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local get_position = function()
|
||||||
|
if Config.layout == "vertical" then
|
||||||
|
return "bottom"
|
||||||
|
end
|
||||||
|
return "right"
|
||||||
|
end
|
||||||
|
|
||||||
|
local get_size = function()
|
||||||
|
if Config.layout == "vertical" then
|
||||||
|
return {
|
||||||
|
height = 8,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
width = "40%",
|
||||||
|
height = api.nvim_win_get_height(self.result.winid),
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
self.input = Split({
|
self.input = Split({
|
||||||
enter = false,
|
enter = false,
|
||||||
relative = {
|
relative = {
|
||||||
@ -1381,10 +1401,8 @@ function Sidebar:create_input()
|
|||||||
winid = self.result.winid,
|
winid = self.result.winid,
|
||||||
},
|
},
|
||||||
win_options = vim.tbl_deep_extend("force", get_win_options(), { signcolumn = "yes" }),
|
win_options = vim.tbl_deep_extend("force", get_win_options(), { signcolumn = "yes" }),
|
||||||
position = "bottom",
|
position = get_position(),
|
||||||
size = {
|
size = get_size(),
|
||||||
height = 8,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
local function on_submit()
|
local function on_submit()
|
||||||
@ -1567,12 +1585,39 @@ function Sidebar:render()
|
|||||||
local chat_history = History.load(self.code.bufnr)
|
local chat_history = History.load(self.code.bufnr)
|
||||||
|
|
||||||
local sidebar_height = api.nvim_win_get_height(self.code.winid)
|
local sidebar_height = api.nvim_win_get_height(self.code.winid)
|
||||||
local selected_code_size = self:get_selected_code_size()
|
local get_position = function()
|
||||||
|
if Config.layout == "vertical" then
|
||||||
|
return "right"
|
||||||
|
end
|
||||||
|
return "bottom"
|
||||||
|
end
|
||||||
|
|
||||||
|
local get_height = function()
|
||||||
|
local selected_code_size = self:get_selected_code_size()
|
||||||
|
vim.print(selected_code_size)
|
||||||
|
if Config.layout == "horizontal" then
|
||||||
|
return math.floor(Config.windows.height / 100 * api.nvim_win_get_height(self.code.winid))
|
||||||
|
end
|
||||||
|
|
||||||
|
if Config.layout == "vertical" then
|
||||||
|
return math.max(1, api.nvim_win_get_height(self.code.winid) - selected_code_size - 3 - 8)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local get_width = function()
|
||||||
|
if Config.layout == "vertical" then
|
||||||
|
return math.floor(Config.windows.width / 100 * api.nvim_win_get_width(self.code.winid))
|
||||||
|
end
|
||||||
|
|
||||||
|
if Config.layout == "horizontal" then
|
||||||
|
return math.max(1, api.nvim_win_get_width(self.code.winid))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
self.result = Split({
|
self.result = Split({
|
||||||
enter = false,
|
enter = false,
|
||||||
relative = "editor",
|
relative = "editor",
|
||||||
position = "right",
|
position = get_position(),
|
||||||
buf_options = vim.tbl_deep_extend("force", buf_options, {
|
buf_options = vim.tbl_deep_extend("force", buf_options, {
|
||||||
modifiable = false,
|
modifiable = false,
|
||||||
swapfile = false,
|
swapfile = false,
|
||||||
@ -1582,8 +1627,8 @@ function Sidebar:render()
|
|||||||
}),
|
}),
|
||||||
win_options = get_win_options(),
|
win_options = get_win_options(),
|
||||||
size = {
|
size = {
|
||||||
width = string.format("%d%%", Config.windows.width),
|
width = get_width(),
|
||||||
height = math.max(1, sidebar_height - selected_code_size - 3 - 8),
|
height = get_height(),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user