feat: override timeoutlen while hovering over diff (#781)
This commit is contained in:
parent
f8d80d87c5
commit
19ab7d51d5
@ -284,6 +284,10 @@ _See [config.lua#L9](./lua/avante/config.lua) for the full config_
|
||||
autojump = true,
|
||||
---@type string | fun(): any
|
||||
list_opener = "copen",
|
||||
--- Override the 'timeoutlen' setting while hovering over a diff (see :help timeoutlen).
|
||||
--- Helps to avoid entering operator-pending mode with diff mappings starting with `c`.
|
||||
--- Disable by setting to -1.
|
||||
override_timeoutlen = 500,
|
||||
},
|
||||
}
|
||||
```
|
||||
|
@ -186,6 +186,10 @@ Respect and use existing conventions, libraries, etc that are already present in
|
||||
--- @class AvanteConflictConfig
|
||||
diff = {
|
||||
autojump = true,
|
||||
--- Override the 'timeoutlen' setting while hovering over a diff (see :help timeoutlen).
|
||||
--- Helps to avoid entering operator-pending mode with diff mappings starting with `c`.
|
||||
--- Disable by setting to -1.
|
||||
override_timeoutlen = 500,
|
||||
},
|
||||
--- @class AvanteHintsConfig
|
||||
hints = {
|
||||
|
@ -299,15 +299,16 @@ local function register_cursor_move_events(bufnr)
|
||||
})
|
||||
end
|
||||
|
||||
api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, {
|
||||
api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI", "WinLeave" }, {
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
callback = function(event)
|
||||
local position = get_current_position(bufnr)
|
||||
|
||||
if position then
|
||||
if (event.event == "CursorMoved" or event.event == "CursorMovedI") and position then
|
||||
show_keybinding_hint(position.current.range_start + 1)
|
||||
M.override_timeoutlen(bufnr)
|
||||
else
|
||||
api.nvim_buf_clear_namespace(bufnr, KEYBINDING_NAMESPACE, 0, -1)
|
||||
M.restore_timeoutlen(bufnr)
|
||||
end
|
||||
end,
|
||||
})
|
||||
@ -377,6 +378,24 @@ H.clear_buffer_mappings = function(bufnr)
|
||||
if vim.fn.hasmapto(mapping, "n") > 0 then api.nvim_buf_del_keymap(bufnr, "n", mapping) end
|
||||
end
|
||||
vim.b[bufnr].avante_conflict_mappings_set = false
|
||||
M.restore_timeoutlen(bufnr)
|
||||
end
|
||||
|
||||
---@param bufnr integer
|
||||
M.override_timeoutlen = function(bufnr)
|
||||
if vim.b[bufnr].avante_original_timeoutlen then return end
|
||||
if Config.diff.override_timeoutlen > 0 then
|
||||
vim.b[bufnr].avante_original_timeoutlen = vim.o.timeoutlen
|
||||
vim.o.timeoutlen = Config.diff.override_timeoutlen
|
||||
end
|
||||
end
|
||||
|
||||
---@param bufnr integer
|
||||
M.restore_timeoutlen = function(bufnr)
|
||||
if vim.b[bufnr].avante_original_timeoutlen then
|
||||
vim.o.timeoutlen = vim.b[bufnr].avante_original_timeoutlen
|
||||
vim.b[bufnr].avante_original_timeoutlen = nil
|
||||
end
|
||||
end
|
||||
|
||||
M.augroup = api.nvim_create_augroup(AUGROUP_NAME, { clear = true })
|
||||
|
Loading…
x
Reference in New Issue
Block a user