fix: cannot recreate sidebar
This commit is contained in:
parent
93b0fa7318
commit
505fd39151
@ -16,6 +16,7 @@ local function create_result_buf()
|
|||||||
api.nvim_set_option_value("buftype", "nofile", { buf = buf })
|
api.nvim_set_option_value("buftype", "nofile", { buf = buf })
|
||||||
api.nvim_set_option_value("swapfile", false, { buf = buf })
|
api.nvim_set_option_value("swapfile", false, { buf = buf })
|
||||||
api.nvim_set_option_value("modifiable", false, { buf = buf })
|
api.nvim_set_option_value("modifiable", false, { buf = buf })
|
||||||
|
api.nvim_set_option_value("bufhidden", "wipe", { buf = buf })
|
||||||
api.nvim_buf_set_name(buf, RESULT_BUF_NAME)
|
api.nvim_buf_set_name(buf, RESULT_BUF_NAME)
|
||||||
return buf
|
return buf
|
||||||
end
|
end
|
||||||
@ -49,11 +50,6 @@ local function is_code_buf(buf)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local signal = n.create_signal({
|
|
||||||
is_loading = false,
|
|
||||||
text = "",
|
|
||||||
})
|
|
||||||
|
|
||||||
local _cur_code_buf = nil
|
local _cur_code_buf = nil
|
||||||
|
|
||||||
local function get_cur_code_buf()
|
local function get_cur_code_buf()
|
||||||
@ -455,16 +451,50 @@ local function get_conflict_content(content, snippets)
|
|||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local get_renderer_size_and_position = function()
|
||||||
local renderer_width = math.ceil(vim.o.columns * 0.3)
|
local renderer_width = math.ceil(vim.o.columns * 0.3)
|
||||||
|
local renderer_height = vim.o.lines
|
||||||
|
local renderer_position = vim.o.columns - renderer_width
|
||||||
|
return renderer_width, renderer_height, renderer_position
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.render_sidebar()
|
||||||
|
if result_buf ~= nil and api.nvim_buf_is_valid(result_buf) then
|
||||||
|
api.nvim_buf_delete(result_buf, { force = true })
|
||||||
|
end
|
||||||
|
|
||||||
|
result_buf = create_result_buf()
|
||||||
|
|
||||||
|
local renderer_width, renderer_height, renderer_position = get_renderer_size_and_position()
|
||||||
|
|
||||||
local renderer = n.create_renderer({
|
local renderer = n.create_renderer({
|
||||||
width = renderer_width,
|
width = renderer_width,
|
||||||
height = vim.o.lines,
|
height = renderer_height,
|
||||||
position = vim.o.columns - renderer_width,
|
position = renderer_position,
|
||||||
relative = "editor",
|
relative = "editor",
|
||||||
})
|
})
|
||||||
|
|
||||||
function M.render_sidebar()
|
local autocmd_id
|
||||||
|
renderer:on_mount(function()
|
||||||
|
autocmd_id = api.nvim_create_autocmd("VimResized", {
|
||||||
|
callback = function()
|
||||||
|
local width, height, _ = get_renderer_size_and_position()
|
||||||
|
renderer:set_size({ width = width, height = height })
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end)
|
||||||
|
|
||||||
|
renderer:on_unmount(function()
|
||||||
|
if autocmd_id ~= nil then
|
||||||
|
api.nvim_del_autocmd(autocmd_id)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
local signal = n.create_signal({
|
||||||
|
is_loading = false,
|
||||||
|
text = "",
|
||||||
|
})
|
||||||
|
|
||||||
local chat_history = load_chat_history()
|
local chat_history = load_chat_history()
|
||||||
update_result_buf_with_history(chat_history)
|
update_result_buf_with_history(chat_history)
|
||||||
|
|
||||||
@ -555,7 +585,7 @@ function M.render_sidebar()
|
|||||||
n.box(
|
n.box(
|
||||||
{
|
{
|
||||||
direction = "column",
|
direction = "column",
|
||||||
size = vim.o.lines - 3,
|
size = vim.o.lines - 4,
|
||||||
},
|
},
|
||||||
n.buffer({
|
n.buffer({
|
||||||
id = "response",
|
id = "response",
|
||||||
@ -566,6 +596,12 @@ function M.render_sidebar()
|
|||||||
text = "💬 Avante Chat",
|
text = "💬 Avante Chat",
|
||||||
align = "center",
|
align = "center",
|
||||||
},
|
},
|
||||||
|
padding = {
|
||||||
|
top = 1,
|
||||||
|
bottom = 1,
|
||||||
|
left = 1,
|
||||||
|
right = 1,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
n.gap(1),
|
n.gap(1),
|
||||||
@ -590,11 +626,12 @@ function M.render_sidebar()
|
|||||||
handle_submit()
|
handle_submit()
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
padding = { left = 1, right = 1 },
|
||||||
}),
|
}),
|
||||||
n.gap(1),
|
n.gap(1),
|
||||||
n.spinner({
|
n.spinner({
|
||||||
is_loading = signal.is_loading,
|
is_loading = signal.is_loading,
|
||||||
padding = { top = 1, left = 1 },
|
padding = { top = 1, right = 1 },
|
||||||
---@diagnostic disable-next-line: undefined-field
|
---@diagnostic disable-next-line: undefined-field
|
||||||
hidden = signal.is_loading:negate(),
|
hidden = signal.is_loading:negate(),
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user