feat: Allow Chat Sidebar to Replace the Main Window (No Split) (#1638)
This commit is contained in:
@@ -101,6 +101,7 @@ 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 no_split? boolean whether to open a new chat without split side bar
|
||||||
|
|
||||||
---@param opts? AskOptions
|
---@param opts? AskOptions
|
||||||
function M.ask(opts)
|
function M.ask(opts)
|
||||||
|
|||||||
@@ -140,12 +140,18 @@ end
|
|||||||
function Sidebar:close(opts)
|
function Sidebar:close(opts)
|
||||||
opts = vim.tbl_extend("force", { goto_code_win = true }, opts or {})
|
opts = vim.tbl_extend("force", { goto_code_win = true }, opts or {})
|
||||||
self:delete_autocmds()
|
self:delete_autocmds()
|
||||||
|
|
||||||
|
if opts.goto_code_win and self.code then
|
||||||
|
if self.code.winid and api.nvim_win_is_valid(self.code.winid) then
|
||||||
|
fn.win_gotoid(self.code.winid)
|
||||||
|
else
|
||||||
|
vim.cmd("vert sb" .. self.code.bufnr)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
for _, comp in pairs(self) do
|
for _, comp in pairs(self) do
|
||||||
if comp and type(comp) == "table" and comp.unmount then comp:unmount() end
|
if comp and type(comp) == "table" and comp.unmount then comp:unmount() end
|
||||||
end
|
end
|
||||||
if opts.goto_code_win and self.code and self.code.winid and api.nvim_win_is_valid(self.code.winid) then
|
|
||||||
fn.win_gotoid(self.code.winid)
|
|
||||||
end
|
|
||||||
|
|
||||||
vim.cmd("wincmd =")
|
vim.cmd("wincmd =")
|
||||||
end
|
end
|
||||||
@@ -2994,8 +3000,6 @@ function Sidebar:create_input_container(opts)
|
|||||||
if ev.data and ev.data.request then handle_submit(ev.data.request) end
|
if ev.data and ev.data.request then handle_submit(ev.data.request) end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
self:refresh_winids()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Sidebar:get_selected_code_size()
|
function Sidebar:get_selected_code_size()
|
||||||
@@ -3040,11 +3044,13 @@ function Sidebar:get_result_container_width()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Sidebar:adjust_result_container_layout()
|
function Sidebar:adjust_result_container_layout()
|
||||||
local width = self:get_result_container_width()
|
if self.code.winid ~= nil and api.nvim_win_is_valid(self.code.winid) then
|
||||||
local height = self:get_result_container_height()
|
local width = self:get_result_container_width()
|
||||||
|
local height = self:get_result_container_height()
|
||||||
|
|
||||||
api.nvim_win_set_width(self.result_container.winid, width)
|
api.nvim_win_set_width(self.result_container.winid, width)
|
||||||
api.nvim_win_set_height(self.result_container.winid, height)
|
api.nvim_win_set_height(self.result_container.winid, height)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param opts AskOptions
|
---@param opts AskOptions
|
||||||
@@ -3089,19 +3095,27 @@ function Sidebar:render(opts)
|
|||||||
|
|
||||||
self:update_content_with_history()
|
self:update_content_with_history()
|
||||||
|
|
||||||
-- reset states when buffer is closed
|
if opts.no_split == true then
|
||||||
api.nvim_buf_attach(self.code.bufnr, false, {
|
vim.cmd(fn.win_getid(self.code.winid) .. "wincmd q")
|
||||||
on_detach = function(_, _)
|
self.code.winid = nil
|
||||||
vim.schedule(function()
|
fn.win_gotoid(self.input_container.winid)
|
||||||
local bufnr = api.nvim_win_get_buf(self.code.winid)
|
else
|
||||||
self.code.bufnr = bufnr
|
-- reset states when buffer is closed
|
||||||
self:reload_chat_history()
|
api.nvim_buf_attach(self.code.bufnr, false, {
|
||||||
end)
|
on_detach = function(_, _)
|
||||||
end,
|
vim.schedule(function()
|
||||||
})
|
local bufnr = api.nvim_win_get_buf(self.code.winid)
|
||||||
|
self.code.bufnr = bufnr
|
||||||
|
self:reload_chat_history()
|
||||||
|
end)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
self:create_selected_code_container()
|
self:create_selected_code_container()
|
||||||
|
|
||||||
|
self:refresh_winids()
|
||||||
|
|
||||||
self:on_mount(opts)
|
self:on_mount(opts)
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|||||||
Reference in New Issue
Block a user