Skip to content

Commit

Permalink
fix(sidebar): allow /clear to be run multiple times (#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddillert committed Sep 15, 2024
1 parent bcec0fa commit ff5d27a
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lua/avante/sidebar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ff5d27a

Please sign in to comment.