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 if cb then cb(args) end
end, end,
clear = function(args, cb) clear = function(args, cb)
local chat_history = {} local chat_history = Path.history.load(self.code.bufnr)
Path.history.save(self.code.bufnr, chat_history) if next(chat_history) ~= nil then
self:update_content("Chat history cleared", { focus = false, scroll = false }) chat_history = {}
vim.defer_fn(function() Path.history.save(self.code.bufnr, chat_history)
self:close() self:update_content("Chat history cleared", { focus = false, scroll = false })
if cb then cb(args) end vim.defer_fn(function()
end, 1000) 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, end,
lines = function(args, cb) lines = function(args, cb)
if cb then cb(args) end if cb then cb(args) end