chore(keymaps): add toggle options (#204)
Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
parent
46ec0a50a7
commit
305d972849
@ -107,6 +107,10 @@ M.defaults = {
|
||||
normal = "<CR>",
|
||||
insert = "<C-s>",
|
||||
},
|
||||
toggle = {
|
||||
debug = "<leader>ad",
|
||||
hint = "<leader>ah",
|
||||
},
|
||||
},
|
||||
windows = {
|
||||
wrap = true, -- similar to vim.o.wrap
|
||||
@ -118,7 +122,6 @@ M.defaults = {
|
||||
},
|
||||
--- @class AvanteConflictUserConfig
|
||||
diff = {
|
||||
debug = false,
|
||||
autojump = true,
|
||||
---@type string | fun(): any
|
||||
list_opener = "copen",
|
||||
|
@ -329,7 +329,7 @@ local function register_cursor_move_events(bufnr)
|
||||
end
|
||||
|
||||
local hint = string.format(
|
||||
" [Press <%s> for OURS, <%s> for THEIRS, <%s> for BOTH, <%s> for PREV, <%s> for NEXT] ",
|
||||
"[<%s> for OURS, <%s> for THEIRS, <%s> for BOTH, <%s> for PREV, <%s> for NEXT]",
|
||||
Config.diff.mappings.ours,
|
||||
Config.diff.mappings.theirs,
|
||||
Config.diff.mappings.both,
|
||||
|
@ -43,6 +43,25 @@ end
|
||||
H.keymaps = function()
|
||||
vim.keymap.set({ "n", "v" }, Config.mappings.ask, M.toggle, { noremap = true })
|
||||
vim.keymap.set("n", Config.mappings.refresh, M.refresh, { noremap = true })
|
||||
|
||||
Utils.toggle_map("n", Config.mappings.toggle.debug, {
|
||||
name = "debug",
|
||||
get = function()
|
||||
return Config.debug
|
||||
end,
|
||||
set = function(state)
|
||||
Config.override({ debug = state })
|
||||
end,
|
||||
})
|
||||
Utils.toggle_map("n", Config.mappings.toggle.hint, {
|
||||
name = "hint",
|
||||
get = function()
|
||||
return Config.hints.enabled
|
||||
end,
|
||||
set = function(state)
|
||||
Config.override({ hints = { enabled = state } })
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
H.autocmds = function()
|
||||
|
@ -43,7 +43,7 @@ end
|
||||
function Selection:show_hints_popup()
|
||||
self:close_hints_popup()
|
||||
|
||||
local hint_text = string.format(" [Ask %s] ", Config.mappings.ask)
|
||||
local hint_text = string.format(" [%s: ask avante] ", Config.mappings.ask)
|
||||
|
||||
local virt_text_line = self:get_virt_text_line()
|
||||
|
||||
|
@ -492,7 +492,7 @@ function Sidebar:on_mount()
|
||||
|
||||
current_apply_extmark_id =
|
||||
api.nvim_buf_set_extmark(self.result.bufnr, CODEBLOCK_KEYBINDING_NAMESPACE, block.start_line, -1, {
|
||||
virt_text = { { " [Press <A> to Apply these patches] ", "Keyword" } },
|
||||
virt_text = { { " [<A>: apply patch] ", "Keyword" } },
|
||||
virt_text_pos = "right_align",
|
||||
hl_group = "Keyword",
|
||||
priority = PRIORITY,
|
||||
@ -1366,9 +1366,8 @@ function Sidebar:create_input()
|
||||
local function show_hint()
|
||||
close_hint() -- Close the existing hint window
|
||||
|
||||
local hint_text = "Press "
|
||||
.. (vim.fn.mode() ~= "i" and Config.mappings.submit.normal or Config.mappings.submit.insert)
|
||||
.. " to submit"
|
||||
local hint_text = vim.fn.mode() ~= "i" and Config.mappings.submit.normal
|
||||
or Config.mappings.submit.insert .. ": submit"
|
||||
|
||||
local buf = api.nvim_create_buf(false, true)
|
||||
api.nvim_buf_set_lines(buf, 0, -1, false, { hint_text })
|
||||
|
@ -24,6 +24,25 @@ M.has = function(plugin)
|
||||
return require("lazy.core.config").plugins[plugin] ~= nil
|
||||
end
|
||||
|
||||
---@alias _ToggleSet fun(state: boolean): nil
|
||||
---@alias _ToggleGet fun(): boolean
|
||||
---
|
||||
---@param lhs string
|
||||
---@param toggle {name: string, set: _ToggleSet, get: _ToggleGet}
|
||||
---@param mode? string | string[]
|
||||
M.toggle_map = function(mode, lhs, toggle)
|
||||
vim.keymap.set(mode or { "n" }, lhs, function()
|
||||
toggle.set(not toggle.get())
|
||||
local state = toggle.get()
|
||||
if state then
|
||||
M.info("enabled: " .. toggle.name, { title = "Avante" })
|
||||
else
|
||||
M.warn("disabled: " .. toggle.name, { title = "Avante" })
|
||||
end
|
||||
return state
|
||||
end, { desc = "toggle(avante): " .. toggle.name })
|
||||
end
|
||||
|
||||
---@param str string
|
||||
---@param opts? {suffix?: string, prefix?: string}
|
||||
function M.trim(str, opts)
|
||||
|
Loading…
x
Reference in New Issue
Block a user