fix: release the cursor when generating (#1109)
This commit is contained in:
parent
b6d4180bb6
commit
76f60794c3
@ -114,13 +114,16 @@ M._defaults = {
|
||||
timeout = 60000, -- Timeout in milliseconds
|
||||
},
|
||||
---Specify the behaviour of avante.nvim
|
||||
---1. auto_apply_diff_after_generation: Whether to automatically apply diff after LLM response.
|
||||
---1. auto_focus_sidebar : Whether to automatically focus the sidebar when opening avante.nvim. Default to true.
|
||||
---2. auto_suggestions = false, -- Whether to enable auto suggestions. Default to false.
|
||||
---3. auto_apply_diff_after_generation: Whether to automatically apply diff after LLM response.
|
||||
--- This would simulate similar behaviour to cursor. Default to false.
|
||||
---2. auto_set_keymaps : Whether to automatically set the keymap for the current line. Default to true.
|
||||
---4. auto_set_keymaps : Whether to automatically set the keymap for the current line. Default to true.
|
||||
--- Note that avante will safely set these keymap. See https://github.com/yetone/avante.nvim/wiki#keymaps-and-api-i-guess for more details.
|
||||
---3. auto_set_highlight_group : Whether to automatically set the highlight group for the current line. Default to true.
|
||||
---4. support_paste_from_clipboard : Whether to support pasting image from clipboard. This will be determined automatically based whether img-clip is available or not.
|
||||
---5. minimize_diff : Whether to remove unchanged lines when applying a code block
|
||||
---5. auto_set_highlight_group : Whether to automatically set the highlight group for the current line. Default to true.
|
||||
---6. jump_to_result_buffer_on_finish = false, -- Whether to automatically jump to the result buffer after generation
|
||||
---7. support_paste_from_clipboard : Whether to support pasting image from clipboard. This will be determined automatically based whether img-clip is available or not.
|
||||
---8. minimize_diff : Whether to remove unchanged lines when applying a code block
|
||||
behaviour = {
|
||||
auto_focus_sidebar = true,
|
||||
auto_suggestions = false, -- Experimental stage
|
||||
@ -128,6 +131,7 @@ M._defaults = {
|
||||
auto_set_highlight_group = true,
|
||||
auto_set_keymaps = true,
|
||||
auto_apply_diff_after_generation = false,
|
||||
jump_result_buffer_on_finish = false,
|
||||
support_paste_from_clipboard = false,
|
||||
minimize_diff = true,
|
||||
},
|
||||
|
@ -86,6 +86,7 @@ function Sidebar:open(opts)
|
||||
self:initialize()
|
||||
if opts.selection then self.code.selection = opts.selection end
|
||||
self:render(opts)
|
||||
self:focus()
|
||||
else
|
||||
if in_visual_mode or opts.selection then
|
||||
self:close()
|
||||
@ -1049,7 +1050,9 @@ function Sidebar:on_mount(opts)
|
||||
and api.nvim_win_is_valid(self.input_container.winid)
|
||||
then
|
||||
api.nvim_set_current_win(self.input_container.winid)
|
||||
if Config.windows.ask.start_insert then vim.cmd("startinsert") end
|
||||
vim.schedule(function()
|
||||
if Config.windows.ask.start_insert then vim.cmd("startinsert") end
|
||||
end)
|
||||
end
|
||||
end
|
||||
return true
|
||||
@ -1202,7 +1205,7 @@ end
|
||||
---@param opts? {focus?: boolean, scroll?: boolean, backspace?: integer, ignore_history?: boolean, callback?: fun(): nil} whether to focus the result view
|
||||
function Sidebar:update_content(content, opts)
|
||||
if not self.result_container or not self.result_container.bufnr then return end
|
||||
opts = vim.tbl_deep_extend("force", { focus = true, scroll = true, stream = false, callback = nil }, opts or {})
|
||||
opts = vim.tbl_deep_extend("force", { focus = false, scroll = true, stream = false, callback = nil }, opts or {})
|
||||
if not opts.ignore_history then
|
||||
local chat_history = Path.history.load(self.code.bufnr)
|
||||
content = self:render_history_content(chat_history) .. "---\n\n" .. content
|
||||
@ -1257,7 +1260,7 @@ function Sidebar:update_content(content, opts)
|
||||
Utils.update_buffer_content(self.result_container.bufnr, lines)
|
||||
Utils.lock_buf(self.result_container.bufnr)
|
||||
api.nvim_set_option_value("filetype", "Avante", { buf = self.result_container.bufnr })
|
||||
if opts.focus and Config.behaviour.auto_focus_sidebar and not self:is_focused_on_result() then
|
||||
if opts.focus and not self:is_focused_on_result() then
|
||||
--- set cursor to bottom of result view
|
||||
xpcall(function() api.nvim_set_current_win(self.result_container.winid) end, function(err) return err end)
|
||||
end
|
||||
@ -1719,7 +1722,7 @@ function Sidebar:create_input_container(opts)
|
||||
self.result_container
|
||||
and self.result_container.winid
|
||||
and api.nvim_win_is_valid(self.result_container.winid)
|
||||
and Config.behaviour.auto_focus_sidebar
|
||||
and Config.behaviour.jump_result_buffer_on_finish
|
||||
then
|
||||
api.nvim_set_current_win(self.result_container.winid)
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user