Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lua/CopilotChat/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
---@field highlight_headers boolean?
---@field auto_follow_cursor boolean?
---@field auto_insert_mode boolean?
---@field auto_fold boolean?
---@field insert_at_end boolean?
---@field clear_chat_on_new_prompt boolean?

Expand Down Expand Up @@ -90,6 +91,7 @@ return {
highlight_headers = true, -- Highlight headers in chat
auto_follow_cursor = true, -- Auto-follow cursor in chat
auto_insert_mode = false, -- Automatically enter insert mode when opening window and on new prompt
auto_fold = false, -- Automatically non-assistant messages in chat
insert_at_end = false, -- Move cursor to end of buffer when inserting text
clear_chat_on_new_prompt = false, -- Clears chat on every new prompt

Expand Down
18 changes: 18 additions & 0 deletions lua/CopilotChat/ui/chat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,18 @@ function Chat:add_message(message, replace)
or current_message.role ~= message.role
or (message.id and current_message.id ~= message.id)

if
self.config.auto_fold
and current_message
and current_message.role ~= constants.ROLE.ASSISTANT
and message.role ~= constants.ROLE.USER
and self:visible()
then
vim.api.nvim_win_call(self.winnr, function()
vim.cmd('normal! zc')
end)
end

if is_new then
-- Add appropriate header based on role and generate a new ID if not provided
message.id = message.id or utils.uuid()
Expand Down Expand Up @@ -489,6 +501,12 @@ function Chat:add_message(message, replace)
current_message.content = current_message.content .. message.content
self:append(message.content)
end

if self.config.auto_fold and message.role == constants.ROLE.ASSISTANT and self:visible() then
vim.api.nvim_win_call(self.winnr, function()
vim.cmd('normal! zo')
end)
end
end

--- Remove a message from the chat window by role.
Expand Down
Loading