refactor: remove floating windows (#262)
This commit is contained in:
parent
8fa351f563
commit
50d0748901
@ -64,6 +64,10 @@ H.keymaps = function()
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
H.signs = function()
|
||||||
|
vim.fn.sign_define("AvanteInputPromptSign", { text = "> " })
|
||||||
|
end
|
||||||
|
|
||||||
H.augroup = api.nvim_create_augroup("avante_autocmds", { clear = true })
|
H.augroup = api.nvim_create_augroup("avante_autocmds", { clear = true })
|
||||||
|
|
||||||
H.autocmds = function()
|
H.autocmds = function()
|
||||||
@ -242,6 +246,7 @@ function M.setup(opts)
|
|||||||
H.autocmds()
|
H.autocmds()
|
||||||
H.commands()
|
H.commands()
|
||||||
H.keymaps()
|
H.keymaps()
|
||||||
|
H.signs()
|
||||||
|
|
||||||
M.did_setup = true
|
M.did_setup = true
|
||||||
end
|
end
|
||||||
|
@ -30,13 +30,10 @@ local Sidebar = {}
|
|||||||
---@field registered_cmp boolean
|
---@field registered_cmp boolean
|
||||||
---@field augroup integer
|
---@field augroup integer
|
||||||
---@field code avante.CodeState
|
---@field code avante.CodeState
|
||||||
---@field winids table<string, integer> this table stores the winids of the sidebar components (result_container, result, selected_code_container, selected_code, input_container, input), even though they are destroyed.
|
---@field winids table<string, integer> this table stores the winids of the sidebar components (result, selected_code, input), even though they are destroyed.
|
||||||
---@field result_container NuiSplit | nil
|
---@field result NuiSplit | nil
|
||||||
---@field result FloatingWindow | nil
|
---@field selected_code NuiSplit | nil
|
||||||
---@field selected_code_container NuiSplit | nil
|
---@field input NuiSplit | nil
|
||||||
---@field selected_code FloatingWindow | nil
|
|
||||||
---@field input_container NuiSplit | nil
|
|
||||||
---@field input FloatingWindow | nil
|
|
||||||
|
|
||||||
---@param id integer the tabpage id retrieved from api.nvim_get_current_tabpage()
|
---@param id integer the tabpage id retrieved from api.nvim_get_current_tabpage()
|
||||||
function Sidebar:new(id)
|
function Sidebar:new(id)
|
||||||
@ -45,16 +42,12 @@ function Sidebar:new(id)
|
|||||||
registered_cmp = false,
|
registered_cmp = false,
|
||||||
code = { bufnr = 0, winid = 0, selection = nil },
|
code = { bufnr = 0, winid = 0, selection = nil },
|
||||||
winids = {
|
winids = {
|
||||||
result_container = 0,
|
|
||||||
result = 0,
|
result = 0,
|
||||||
selected_code_container = 0,
|
|
||||||
selected_code = 0,
|
selected_code = 0,
|
||||||
input = 0,
|
input = 0,
|
||||||
},
|
},
|
||||||
result = nil,
|
result = nil,
|
||||||
selected_code_container = nil,
|
|
||||||
selected_code = nil,
|
selected_code = nil,
|
||||||
input_container = nil,
|
|
||||||
input = nil,
|
input = nil,
|
||||||
}, { __index = self })
|
}, { __index = self })
|
||||||
end
|
end
|
||||||
@ -69,12 +62,9 @@ end
|
|||||||
function Sidebar:reset()
|
function Sidebar:reset()
|
||||||
self:delete_autocmds()
|
self:delete_autocmds()
|
||||||
self.code = { bufnr = 0, winid = 0, selection = nil }
|
self.code = { bufnr = 0, winid = 0, selection = nil }
|
||||||
self.winids = { result_container = 0, result = 0, selected_code = 0, input = 0 }
|
self.winids = { result = 0, selected_code = 0, input = 0 }
|
||||||
self.result_container = nil
|
|
||||||
self.result = nil
|
self.result = nil
|
||||||
self.selected_code_container = nil
|
|
||||||
self.selected_code = nil
|
self.selected_code = nil
|
||||||
self.input_container = nil
|
|
||||||
self.input = nil
|
self.input = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -336,79 +326,44 @@ function Sidebar:render_header(winid, bufnr, header_text, hl, reverse_hl)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local reversed_hl_off = 0
|
if not Config.windows.sidebar_header.rounded then
|
||||||
if Config.windows.sidebar_header.rounded then
|
|
||||||
reversed_hl_off = 1
|
|
||||||
header_text = "" .. header_text .. ""
|
|
||||||
else
|
|
||||||
header_text = " " .. header_text .. " "
|
header_text = " " .. header_text .. " "
|
||||||
end
|
end
|
||||||
|
|
||||||
local width = api.nvim_win_get_width(winid)
|
local winbar_text = "%#Normal#"
|
||||||
local header_text_length = vim.fn.strdisplaywidth(header_text)
|
|
||||||
local prefix_padding, suffix_padding = 0, 0
|
|
||||||
|
|
||||||
if Config.windows.sidebar_header.align == "center" then
|
if Config.windows.sidebar_header.align == "center" then
|
||||||
prefix_padding = math.floor((width - header_text_length) / 2)
|
winbar_text = winbar_text .. "%="
|
||||||
suffix_padding = width - header_text_length - prefix_padding
|
|
||||||
elseif Config.windows.sidebar_header.align == "right" then
|
elseif Config.windows.sidebar_header.align == "right" then
|
||||||
prefix_padding = width - header_text_length
|
winbar_text = winbar_text .. "%="
|
||||||
suffix_padding = 0
|
|
||||||
elseif Config.windows.sidebar_header.align == "left" then
|
|
||||||
suffix_padding = width - header_text_length
|
|
||||||
prefix_padding = 0
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local prefix_padding_text = string.rep(" ", prefix_padding)
|
if Config.windows.sidebar_header.rounded then
|
||||||
local suffix_padding_text = string.rep(" ", suffix_padding)
|
winbar_text = winbar_text .. "%#" .. reverse_hl .. "#" .. "" .. "%#" .. hl .. "#"
|
||||||
Utils.unlock_buf(bufnr)
|
else
|
||||||
api.nvim_buf_set_lines(bufnr, 0, -1, false, { prefix_padding_text .. header_text .. suffix_padding_text })
|
winbar_text = winbar_text .. "%#" .. hl .. "#"
|
||||||
api.nvim_buf_add_highlight(bufnr, -1, "WinSeparator", 0, 0, #prefix_padding_text - reversed_hl_off)
|
end
|
||||||
api.nvim_buf_add_highlight(bufnr, -1, reverse_hl, 0, #prefix_padding_text, #prefix_padding_text + reversed_hl_off)
|
winbar_text = winbar_text .. header_text
|
||||||
api.nvim_buf_add_highlight(
|
if Config.windows.sidebar_header.rounded then
|
||||||
bufnr,
|
winbar_text = winbar_text .. "%#" .. reverse_hl .. "#"
|
||||||
-1,
|
end
|
||||||
hl,
|
winbar_text = winbar_text .. "%#Normal#"
|
||||||
0,
|
if Config.windows.sidebar_header.align == "center" then
|
||||||
#prefix_padding_text + reversed_hl_off,
|
winbar_text = winbar_text .. "%="
|
||||||
#prefix_padding_text + #header_text - reversed_hl_off * 3
|
end
|
||||||
)
|
api.nvim_set_option_value("winbar", winbar_text, { win = winid })
|
||||||
api.nvim_buf_add_highlight(
|
|
||||||
bufnr,
|
|
||||||
-1,
|
|
||||||
reverse_hl,
|
|
||||||
0,
|
|
||||||
#prefix_padding_text + #header_text - reversed_hl_off * 3,
|
|
||||||
#prefix_padding_text + #header_text - reversed_hl_off * 2
|
|
||||||
)
|
|
||||||
api.nvim_buf_add_highlight(bufnr, -1, "WinSeparator", 0, #prefix_padding_text + #header_text - reversed_hl_off, -1)
|
|
||||||
Utils.lock_buf(bufnr)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Sidebar:render_result_container()
|
function Sidebar:render_result()
|
||||||
if
|
if not self.result or not self.result.bufnr or not api.nvim_buf_is_valid(self.result.bufnr) then
|
||||||
not self.result_container
|
|
||||||
or not self.result_container.bufnr
|
|
||||||
or not api.nvim_buf_is_valid(self.result_container.bufnr)
|
|
||||||
then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local header_text = " Avante"
|
local header_text = " Avante"
|
||||||
self:render_header(
|
self:render_header(self.result.winid, self.result.bufnr, header_text, Highlights.TITLE, Highlights.REVERSED_TITLE)
|
||||||
self.result_container.winid,
|
|
||||||
self.result_container.bufnr,
|
|
||||||
header_text,
|
|
||||||
Highlights.TITLE,
|
|
||||||
Highlights.REVERSED_TITLE
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Sidebar:render_input_container()
|
function Sidebar:render_input()
|
||||||
if
|
if not self.input or not self.input.bufnr or not api.nvim_buf_is_valid(self.input.bufnr) then
|
||||||
not self.input_container
|
|
||||||
or not self.input_container.bufnr
|
|
||||||
or not api.nvim_buf_is_valid(self.input_container.bufnr)
|
|
||||||
then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -439,20 +394,16 @@ function Sidebar:render_input_container()
|
|||||||
end
|
end
|
||||||
|
|
||||||
self:render_header(
|
self:render_header(
|
||||||
self.input_container.winid,
|
self.input.winid,
|
||||||
self.input_container.bufnr,
|
self.input.bufnr,
|
||||||
header_text,
|
header_text,
|
||||||
Highlights.THIRD_TITLE,
|
Highlights.THIRD_TITLE,
|
||||||
Highlights.REVERSED_THIRD_TITLE
|
Highlights.REVERSED_THIRD_TITLE
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Sidebar:render_selected_code_container()
|
function Sidebar:render_selected_code()
|
||||||
if
|
if not self.selected_code or not self.selected_code.bufnr or not api.nvim_buf_is_valid(self.selected_code.bufnr) then
|
||||||
not self.selected_code_container
|
|
||||||
or not self.selected_code_container.bufnr
|
|
||||||
or not api.nvim_buf_is_valid(self.selected_code_container.bufnr)
|
|
||||||
then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -472,8 +423,8 @@ function Sidebar:render_selected_code_container()
|
|||||||
)
|
)
|
||||||
|
|
||||||
self:render_header(
|
self:render_header(
|
||||||
self.selected_code_container.winid,
|
self.selected_code.winid,
|
||||||
self.selected_code_container.bufnr,
|
self.selected_code.bufnr,
|
||||||
header_text,
|
header_text,
|
||||||
Highlights.SUBTITLE,
|
Highlights.SUBTITLE,
|
||||||
Highlights.REVERSED_SUBTITLE
|
Highlights.REVERSED_SUBTITLE
|
||||||
@ -605,9 +556,9 @@ function Sidebar:on_mount()
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
self:render_result_container()
|
self:render_result()
|
||||||
self:render_input_container()
|
self:render_input()
|
||||||
self:render_selected_code_container()
|
self:render_selected_code()
|
||||||
|
|
||||||
self.augroup = api.nvim_create_augroup("avante_" .. self.id .. self.result.winid, { clear = true })
|
self.augroup = api.nvim_create_augroup("avante_" .. self.id .. self.result.winid, { clear = true })
|
||||||
|
|
||||||
@ -659,89 +610,6 @@ function Sidebar:on_mount()
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
local previous_winid = nil
|
|
||||||
|
|
||||||
api.nvim_create_autocmd("WinLeave", {
|
|
||||||
group = self.augroup,
|
|
||||||
callback = function()
|
|
||||||
previous_winid = api.nvim_get_current_win()
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
api.nvim_create_autocmd("WinEnter", {
|
|
||||||
group = self.augroup,
|
|
||||||
callback = function()
|
|
||||||
local current_win_id = api.nvim_get_current_win()
|
|
||||||
|
|
||||||
if not self.result_container or current_win_id ~= self.result_container.winid then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if previous_winid == self.result.winid and self.input.winid and api.nvim_win_is_valid(self.input.winid) then
|
|
||||||
api.nvim_set_current_win(self.input.winid)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if self.result and self.result.winid and api.nvim_win_is_valid(self.result.winid) then
|
|
||||||
api.nvim_set_current_win(self.result.winid)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
api.nvim_create_autocmd("WinEnter", {
|
|
||||||
group = self.augroup,
|
|
||||||
callback = function()
|
|
||||||
local current_win_id = api.nvim_get_current_win()
|
|
||||||
|
|
||||||
if not self.input_container or current_win_id ~= self.input_container.winid then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if previous_winid == self.input.winid then
|
|
||||||
if self.selected_code and self.selected_code.winid and api.nvim_win_is_valid(self.selected_code.winid) then
|
|
||||||
api.nvim_set_current_win(self.selected_code.winid)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
if self.result and self.result.winid and api.nvim_win_is_valid(self.result.winid) then
|
|
||||||
api.nvim_set_current_win(self.result.winid)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if self.input and self.input.winid and api.nvim_win_is_valid(self.input.winid) then
|
|
||||||
api.nvim_set_current_win(self.input.winid)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
api.nvim_create_autocmd("WinEnter", {
|
|
||||||
group = self.augroup,
|
|
||||||
callback = function()
|
|
||||||
local current_win_id = api.nvim_get_current_win()
|
|
||||||
|
|
||||||
if not self.selected_code_container or current_win_id ~= self.selected_code_container.winid then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if
|
|
||||||
previous_winid == self.result.winid
|
|
||||||
and self.selected_code
|
|
||||||
and self.selected_code.winid
|
|
||||||
and api.nvim_win_is_valid(self.selected_code.winid)
|
|
||||||
then
|
|
||||||
api.nvim_set_current_win(self.selected_code.winid)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if self.result and self.result.winid and api.nvim_win_is_valid(self.result.winid) then
|
|
||||||
api.nvim_set_current_win(self.result.winid)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
for _, comp in pairs(self) do
|
for _, comp in pairs(self) do
|
||||||
if comp and type(comp) == "table" and comp.mount and comp.bufnr and api.nvim_buf_is_valid(comp.bufnr) then
|
if comp and type(comp) == "table" and comp.mount and comp.bufnr and api.nvim_buf_is_valid(comp.bufnr) then
|
||||||
Utils.mark_as_sidebar_buffer(comp.bufnr)
|
Utils.mark_as_sidebar_buffer(comp.bufnr)
|
||||||
@ -778,7 +646,7 @@ function Sidebar:refresh_winids()
|
|||||||
end
|
end
|
||||||
local winid = winids[current_idx]
|
local winid = winids[current_idx]
|
||||||
if winid and api.nvim_win_is_valid(winid) then
|
if winid and api.nvim_win_is_valid(winid) then
|
||||||
api.nvim_set_current_win(winid)
|
pcall(api.nvim_set_current_win, winid)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -814,9 +682,9 @@ function Sidebar:resize()
|
|||||||
api.nvim_win_set_width(comp.winid, new_layout.width)
|
api.nvim_win_set_width(comp.winid, new_layout.width)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self:render_result_container()
|
self:render_result()
|
||||||
self:render_input_container()
|
self:render_input()
|
||||||
self:render_selected_code_container()
|
self:render_selected_code()
|
||||||
vim.defer_fn(function()
|
vim.defer_fn(function()
|
||||||
vim.cmd("AvanteRefresh")
|
vim.cmd("AvanteRefresh")
|
||||||
end, 200)
|
end, 200)
|
||||||
@ -1073,43 +941,31 @@ function Sidebar:create_selected_code()
|
|||||||
self.selected_code:unmount()
|
self.selected_code:unmount()
|
||||||
self.selected_code = nil
|
self.selected_code = nil
|
||||||
end
|
end
|
||||||
if self.selected_code_container ~= nil then
|
|
||||||
self.selected_code_container:unmount()
|
|
||||||
self.selected_code_container = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
local selected_code_size = self:get_selected_code_size()
|
local selected_code_size = self:get_selected_code_size()
|
||||||
|
|
||||||
if self.code.selection ~= nil then
|
if self.code.selection ~= nil then
|
||||||
self.selected_code_container = Split({
|
self.selected_code = Split({
|
||||||
enter = false,
|
enter = false,
|
||||||
relative = {
|
relative = {
|
||||||
type = "win",
|
type = "win",
|
||||||
winid = self.result_container.winid,
|
winid = self.input.winid,
|
||||||
},
|
},
|
||||||
buf_options = buf_options,
|
buf_options = buf_options,
|
||||||
win_options = get_win_options(),
|
win_options = get_win_options(),
|
||||||
position = "bottom",
|
position = "top",
|
||||||
size = {
|
size = {
|
||||||
height = selected_code_size + 3,
|
height = selected_code_size + 3,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
self.selected_code_container:mount()
|
|
||||||
self.selected_code = self:create_floating_window_for_split({ split_winid = self.selected_code_container.winid })
|
|
||||||
self.selected_code:mount()
|
self.selected_code:mount()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Sidebar:create_input()
|
local input_prompt_ns = vim.api.nvim_create_namespace("avante_input_prompt")
|
||||||
if
|
|
||||||
not self.input_container
|
|
||||||
or not self.input_container.winid
|
|
||||||
or not api.nvim_win_is_valid(self.input_container.winid)
|
|
||||||
then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if self.input ~= nil then
|
function Sidebar:create_input()
|
||||||
|
if self.input then
|
||||||
self.input:unmount()
|
self.input:unmount()
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1247,26 +1103,19 @@ function Sidebar:create_input()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if
|
self.input = Split({
|
||||||
not self.input_container
|
enter = false,
|
||||||
or not self.input_container.winid
|
relative = {
|
||||||
or not api.nvim_win_is_valid(self.input_container.winid)
|
type = "win",
|
||||||
then
|
winid = self.result.winid,
|
||||||
return
|
},
|
||||||
end
|
win_options = vim.tbl_deep_extend("force", get_win_options(), { signcolumn = "yes" }),
|
||||||
|
position = "bottom",
|
||||||
self.input = self:create_floating_window_for_split({
|
size = {
|
||||||
split_winid = self.input_container.winid,
|
height = 8,
|
||||||
buf_opts = {
|
|
||||||
modifiable = true,
|
|
||||||
},
|
},
|
||||||
keep_floating_style = true,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
self.input:on_mount(function()
|
|
||||||
api.nvim_win_set_hl_ns(self.input.winid, Highlights.input_ns)
|
|
||||||
end)
|
|
||||||
|
|
||||||
local function on_submit()
|
local function on_submit()
|
||||||
if not vim.g.avante_login then
|
if not vim.g.avante_login then
|
||||||
Utils.warn("Sending message to fast!, API key is not yet set", { title = "Avante" })
|
Utils.warn("Sending message to fast!, API key is not yet set", { title = "Avante" })
|
||||||
@ -1286,6 +1135,22 @@ function Sidebar:create_input()
|
|||||||
|
|
||||||
self.input:mount()
|
self.input:mount()
|
||||||
|
|
||||||
|
local function place_sign_at_first_line(bufnr)
|
||||||
|
local group = "avante_input_prompt_group"
|
||||||
|
|
||||||
|
vim.fn.sign_unplace(group, { buffer = bufnr })
|
||||||
|
|
||||||
|
vim.fn.sign_place(0, group, "AvanteInputPromptSign", bufnr, { lnum = 1 })
|
||||||
|
end
|
||||||
|
|
||||||
|
place_sign_at_first_line(self.input.bufnr)
|
||||||
|
api.nvim_win_set_hl_ns(self.input.winid, Highlights.input_ns)
|
||||||
|
|
||||||
|
if Utils.in_visual_mode() then
|
||||||
|
-- Exit visual mode
|
||||||
|
api.nvim_feedkeys(api.nvim_replace_termcodes("<Esc>", true, false, true), "n", true)
|
||||||
|
end
|
||||||
|
|
||||||
self.input:map("n", Config.mappings.submit.normal, on_submit)
|
self.input:map("n", Config.mappings.submit.normal, on_submit)
|
||||||
self.input:map("i", Config.mappings.submit.insert, on_submit)
|
self.input:map("i", Config.mappings.submit.insert, on_submit)
|
||||||
|
|
||||||
@ -1336,6 +1201,7 @@ function Sidebar:create_input()
|
|||||||
|
|
||||||
-- Get the current window size
|
-- Get the current window size
|
||||||
local win_width = api.nvim_win_get_width(self.input.winid)
|
local win_width = api.nvim_win_get_width(self.input.winid)
|
||||||
|
local buf_height = api.nvim_buf_line_count(self.input.bufnr)
|
||||||
local width = #hint_text
|
local width = #hint_text
|
||||||
|
|
||||||
-- Set the floating window options
|
-- Set the floating window options
|
||||||
@ -1344,8 +1210,8 @@ function Sidebar:create_input()
|
|||||||
win = self.input.winid,
|
win = self.input.winid,
|
||||||
width = width,
|
width = width,
|
||||||
height = 1,
|
height = 1,
|
||||||
row = -1,
|
row = buf_height,
|
||||||
col = math.max(win_width - width, 0), -- Display in the top right corner
|
col = math.max(win_width - width, 0), -- Display in the bottom right corner
|
||||||
style = "minimal",
|
style = "minimal",
|
||||||
border = "none",
|
border = "none",
|
||||||
focusable = false,
|
focusable = false,
|
||||||
@ -1358,8 +1224,24 @@ function Sidebar:create_input()
|
|||||||
api.nvim_win_set_hl_ns(hint_window, Highlights.hint_ns)
|
api.nvim_win_set_hl_ns(hint_window, Highlights.hint_ns)
|
||||||
end
|
end
|
||||||
|
|
||||||
self.input:on_mount(show_hint)
|
show_hint()
|
||||||
self.input:on_unmount(close_hint)
|
|
||||||
|
api.nvim_create_autocmd({ "TextChanged", "TextChangedI" }, {
|
||||||
|
group = self.augroup,
|
||||||
|
buffer = self.input.bufnr,
|
||||||
|
callback = function()
|
||||||
|
show_hint()
|
||||||
|
place_sign_at_first_line(self.input.bufnr)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
api.nvim_create_autocmd("QuitPre", {
|
||||||
|
group = self.augroup,
|
||||||
|
buffer = self.input.bufnr,
|
||||||
|
callback = function()
|
||||||
|
close_hint()
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
-- Show hint in insert mode
|
-- Show hint in insert mode
|
||||||
api.nvim_create_autocmd("ModeChanged", {
|
api.nvim_create_autocmd("ModeChanged", {
|
||||||
@ -1442,28 +1324,20 @@ function Sidebar:render()
|
|||||||
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 selected_code_size = self:get_selected_code_size()
|
||||||
|
|
||||||
self.result_container = Split({
|
self.result = Split({
|
||||||
|
enter = false,
|
||||||
relative = "editor",
|
relative = "editor",
|
||||||
position = "right",
|
position = "right",
|
||||||
buf_options = buf_options,
|
buf_options = vim.tbl_deep_extend("force", buf_options, {
|
||||||
win_options = get_win_options(),
|
|
||||||
size = {
|
|
||||||
width = string.format("%d%%", Config.windows.width),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
self.result_container:mount()
|
|
||||||
|
|
||||||
self.result = self:create_floating_window_for_split({
|
|
||||||
split_winid = self.result_container.winid,
|
|
||||||
buf_opts = {
|
|
||||||
modifiable = false,
|
modifiable = false,
|
||||||
swapfile = false,
|
swapfile = false,
|
||||||
buftype = "nofile",
|
buftype = "nofile",
|
||||||
bufhidden = "wipe",
|
bufhidden = "wipe",
|
||||||
filetype = "Avante",
|
filetype = "Avante",
|
||||||
},
|
}),
|
||||||
float_opts = {
|
win_options = get_win_options(),
|
||||||
|
size = {
|
||||||
|
width = string.format("%d%%", Config.windows.width),
|
||||||
height = math.max(1, sidebar_height - selected_code_size - 3 - 8),
|
height = math.max(1, sidebar_height - selected_code_size - 3 - 8),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -1486,18 +1360,7 @@ function Sidebar:render()
|
|||||||
self:close()
|
self:close()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
self.input_container = Split({
|
self:create_input()
|
||||||
enter = false,
|
|
||||||
relative = {
|
|
||||||
type = "win",
|
|
||||||
winid = self.result_container.winid,
|
|
||||||
},
|
|
||||||
buf_options = buf_options,
|
|
||||||
win_options = get_win_options(),
|
|
||||||
position = "bottom",
|
|
||||||
})
|
|
||||||
|
|
||||||
self.input_container:mount()
|
|
||||||
|
|
||||||
self:update_content_with_history(chat_history)
|
self:update_content_with_history(chat_history)
|
||||||
|
|
||||||
@ -1508,8 +1371,6 @@ function Sidebar:render()
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
self:create_input()
|
|
||||||
|
|
||||||
self:create_selected_code()
|
self:create_selected_code()
|
||||||
|
|
||||||
self:on_mount()
|
self:on_mount()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user