From 0d26590389ff7ab892bf67a411961e43d94f4e6a Mon Sep 17 00:00:00 2001 From: William Kang <68660379+Sokole1@users.noreply.github.com> Date: Sun, 13 Apr 2025 22:11:58 +0900 Subject: [PATCH] docs: Avante Chat History Selector Documentation and Commands (#1862) --- README.md | 5 ++++- lua/avante/history_selector.lua | 16 ++++++++++++++-- plugin/avante.lua | 5 +++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c505376..2895546 100644 --- a/README.md +++ b/README.md @@ -622,6 +622,7 @@ The following key bindings are available for use with `avante.nvim`: | Leadera? | select model | | Leaderae | edit selected blocks | | LeaderaS | stop current AI request | +| Leaderah | select between chat histories | | co | choose ours | | ct | choose theirs | | ca | choose all theirs | @@ -696,7 +697,9 @@ return { | `:AvanteAsk [question] [position]` | Ask AI about your code. Optional `position` set window position and `ask` enable/disable direct asking mode | `:AvanteAsk position=right Refactor this code here` | | `:AvanteBuild` | Build dependencies for the project | | | `:AvanteChat` | Start a chat session with AI about your codebase. Default is `ask`=false | | -| `:AvanteClear` | Clear the chat history | | +| `:AvanteChatNew` | Start a new chat session. The current chat can be re-opened with the chat session selector | | +| `:AvanteHistory` | Opens a picker for your previous chat sessions | | +| `:AvanteClear` | Clear the chat history for your current chat session | | | `:AvanteEdit` | Edit the selected code blocks | | | `:AvanteFocus` | Switch focus to/from the sidebar | | | `:AvanteRefresh` | Refresh all Avante windows | | diff --git a/lua/avante/history_selector.lua b/lua/avante/history_selector.lua index c88981b..0211244 100644 --- a/lua/avante/history_selector.lua +++ b/lua/avante/history_selector.lua @@ -52,8 +52,20 @@ function M.open(bufnr, cb) local history = Path.history.load(vim.api.nvim_get_current_buf(), item.filename) local Sidebar = require("avante.sidebar") local content = Sidebar.render_history_content(history) - vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, vim.split(content or "", "\n")) - vim.api.nvim_set_option_value("filetype", "markdown", { buf = self.state.bufnr }) + local lines = vim.split(content or "", "\n") + -- Ensure the buffer exists and is valid before setting lines + if vim.api.nvim_buf_is_valid(self.state.bufnr) then + vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, lines) + -- Set filetype after content is loaded + vim.api.nvim_set_option_value("filetype", "markdown", { buf = self.state.bufnr }) + -- Ensure cursor is within bounds + vim.schedule(function() + if vim.api.nvim_buf_is_valid(self.state.bufnr) then + local row = math.min(vim.api.nvim_buf_line_count(self.state.bufnr), 1) + pcall(vim.api.nvim_win_set_cursor, self.state.winnr, { row, 0 }) + end + end) + end end, }), attach_mappings = function(prompt_bufnr, map) diff --git a/plugin/avante.lua b/plugin/avante.lua index 177b726..87a7eb7 100644 --- a/plugin/avante.lua +++ b/plugin/avante.lua @@ -85,6 +85,11 @@ end, { end, }) cmd("Chat", function() require("avante.api").ask({ ask = false }) end, { desc = "avante: chat with the codebase" }) +cmd( + "ChatNew", + function() require("avante.api").ask({ ask = false, new_chat = true }) end, + { desc = "avante: create new chat" } +) cmd("Toggle", function() require("avante").toggle() end, { desc = "avante: toggle AI panel" }) cmd("Build", function(opts) local args = {}