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,
|
autojump = true,
|
||||||
---@type string | fun(): any
|
---@type string | fun(): any
|
||||||
list_opener = "copen",
|
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
|
--- @class AvanteConflictConfig
|
||||||
diff = {
|
diff = {
|
||||||
autojump = true,
|
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
|
--- @class AvanteHintsConfig
|
||||||
hints = {
|
hints = {
|
||||||
|
@ -299,15 +299,16 @@ local function register_cursor_move_events(bufnr)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, {
|
api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI", "WinLeave" }, {
|
||||||
buffer = bufnr,
|
buffer = bufnr,
|
||||||
callback = function()
|
callback = function(event)
|
||||||
local position = get_current_position(bufnr)
|
local position = get_current_position(bufnr)
|
||||||
|
if (event.event == "CursorMoved" or event.event == "CursorMovedI") and position then
|
||||||
if position then
|
|
||||||
show_keybinding_hint(position.current.range_start + 1)
|
show_keybinding_hint(position.current.range_start + 1)
|
||||||
|
M.override_timeoutlen(bufnr)
|
||||||
else
|
else
|
||||||
api.nvim_buf_clear_namespace(bufnr, KEYBINDING_NAMESPACE, 0, -1)
|
api.nvim_buf_clear_namespace(bufnr, KEYBINDING_NAMESPACE, 0, -1)
|
||||||
|
M.restore_timeoutlen(bufnr)
|
||||||
end
|
end
|
||||||
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
|
if vim.fn.hasmapto(mapping, "n") > 0 then api.nvim_buf_del_keymap(bufnr, "n", mapping) end
|
||||||
end
|
end
|
||||||
vim.b[bufnr].avante_conflict_mappings_set = false
|
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
|
end
|
||||||
|
|
||||||
M.augroup = api.nvim_create_augroup(AUGROUP_NAME, { clear = true })
|
M.augroup = api.nvim_create_augroup(AUGROUP_NAME, { clear = true })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user