feat!(selection): do not display hint immediately

Selection hint that is displayed immediately upon entering visual mode
([<leader>aa: ask, <leader>ae: edit]) gets old pretty quickly. Add a
config option to control when the hint is displayed:

  selection = {
    enabled = true,
    hint_display = "delayed",
  },

The "hint_display" option recognizes the following values:

- "immediate" results in the hint being shown immediately after entering
  visual mode. This is the old behavior.
- "delayed" causes the hint be displayed only if the cursor has not been
  moved for vim.o.updatetime milliseconds. This is the new default.
- "none" suppresses showing the hint completely.

Unfortunately "CursorHold" event is not emitted in visual mode so we
have to emulate it using Utils.debounce().

This is a breaking change because selection behavior was controller by
"hints" config entry which makes little sense, so the config section and
associated commands were renamed to "selection".

Additionally the "hints"/"selection" was mapped to "<leader>ah", but the
very same key combination was used to select from old Avante chat
histories, which overrode the toggle. New selection toggle keymap is
"<leader>aC".
This commit is contained in:
Dmitry Torokhov
2025-07-25 17:48:42 -07:00
committed by yetone
parent bd2079a5cc
commit fed6902c9a
5 changed files with 55 additions and 19 deletions

View File

@@ -75,7 +75,7 @@ function H.keymaps()
vim.keymap.set("n", "<Plug>(AvanteBuild)", function() require("avante.api").build() end, { noremap = true })
vim.keymap.set("n", "<Plug>(AvanteToggle)", function() M.toggle() end, { noremap = true })
vim.keymap.set("n", "<Plug>(AvanteToggleDebug)", function() M.toggle.debug() end)
vim.keymap.set("n", "<Plug>(AvanteToggleHint)", function() M.toggle.hint() end)
vim.keymap.set("n", "<Plug>(AvanteToggleSelection)", function() M.toggle.selection() end)
vim.keymap.set("n", "<Plug>(AvanteToggleSuggestion)", function() M.toggle.suggestion() end)
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictOurs)", function() Diff.choose("ours") end)
@@ -134,9 +134,9 @@ function H.keymaps()
)
Utils.safe_keymap_set(
"n",
Config.mappings.toggle.hint,
Config.mappings.toggle.selection,
function() M.toggle.hint() end,
{ desc = "avante: toggle hint" }
{ desc = "avante: toggle selection" }
)
Utils.safe_keymap_set(
"n",
@@ -230,7 +230,7 @@ function H.autocmds()
callback = function(ev)
local tab = tonumber(ev.file)
M._init(tab or api.nvim_get_current_tabpage())
if Config.hints.enabled and not M.current.selection.did_setup then M.current.selection:setup_autocmds() end
if Config.selection.enabled and not M.current.selection.did_setup then M.current.selection:setup_autocmds() end
end,
})
@@ -287,7 +287,7 @@ function H.autocmds()
vim.schedule(function()
M._init(api.nvim_get_current_tabpage())
if Config.hints.enabled then M.current.selection:setup_autocmds() end
if Config.selection.enabled then M.current.selection:setup_autocmds() end
end)
local function setup_colors()
@@ -405,10 +405,10 @@ M.toggle.debug = H.api(Utils.toggle_wrap({
set = function(state) Config.override({ debug = state }) end,
}))
M.toggle.hint = H.api(Utils.toggle_wrap({
name = "hint",
get = function() return Config.hints.enabled end,
set = function(state) Config.override({ hints = { enabled = state } }) end,
M.toggle.selection = H.api(Utils.toggle_wrap({
name = "selection",
get = function() return Config.selection.enabled end,
set = function(state) Config.override({ selection = { enabled = state } }) end,
}))
M.toggle.suggestion = H.api(Utils.toggle_wrap({