From 57e4f6ff5474108d1df86c9c5cffaaef23a02268 Mon Sep 17 00:00:00 2001 From: Jonas Widen Date: Sun, 16 Mar 2025 19:21:18 +0100 Subject: [PATCH] Restore chat history --- lua/gemini/chat.lua | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/lua/gemini/chat.lua b/lua/gemini/chat.lua index 6ad3dbd..e803871 100644 --- a/lua/gemini/chat.lua +++ b/lua/gemini/chat.lua @@ -114,25 +114,18 @@ end function M.update_content(content, is_new_chat) vim.api.nvim_buf_set_option(state.bufnr, 'modifiable', true) + local lines = vim.split(content, "\n") + + if #state.conversation_history > 1 then -- Check if there's more than one message + -- Add separator before new content + local separator = "━━━━━━━━━━━━━━━━━━━━━━━━━━" + table.insert(lines, 1, separator) + end + if is_new_chat then - -- Don't clear existing content, append to it - local lines = vim.split(content, "\n") - if #state.conversation_history > 0 then - -- Add separator before new content - local separator = "━━━━━━━━━━━━━━━━━━━━━━━━━━" - table.insert(lines, 1, separator) - -- Get current buffer content - local current_lines = vim.api.nvim_buf_get_lines(state.bufnr, 0, -1, false) - -- Combine existing content with new content - for i = #current_lines, 1, -1 do - table.insert(lines, 1, current_lines[i]) - end - end vim.api.nvim_buf_set_lines(state.bufnr, 0, -1, false, lines) else - local separator = "━━━━━━━━━━━━━━━━━━━━━━━━━━" - vim.api.nvim_buf_set_lines(state.bufnr, -1, -1, false, {separator}) - vim.api.nvim_buf_set_lines(state.bufnr, -1, -1, false, vim.split(content, "\n")) + vim.api.nvim_buf_set_lines(state.bufnr, -1, -1, false, lines) end vim.api.nvim_buf_set_option(state.bufnr, 'modifiable', false)