fix(sidebar): allow /clear to be run multiple times (#579)

This commit is contained in:
Dennis Dillert 2024-09-15 16:56:28 +02:00 committed by GitHub
parent bcec0fa194
commit ff5d27a4cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1096,13 +1096,19 @@ function Sidebar:get_commands()
if cb then cb(args) end
end,
clear = function(args, cb)
local chat_history = {}
Path.history.save(self.code.bufnr, chat_history)
self:update_content("Chat history cleared", { focus = false, scroll = false })
vim.defer_fn(function()
self:close()
if cb then cb(args) end
end, 1000)
local chat_history = Path.history.load(self.code.bufnr)
if next(chat_history) ~= nil then
chat_history = {}
Path.history.save(self.code.bufnr, chat_history)
self:update_content("Chat history cleared", { focus = false, scroll = false })
vim.defer_fn(function()
self:close()
if cb then cb(args) end
end, 1000)
else
self:update_content("Chat history is already empty", { focus = false, scroll = false })
vim.defer_fn(function() self:close() end, 1000)
end
end,
lines = function(args, cb)
if cb then cb(args) end