feat(util.mini): follow the user's mappings instead of hardcoded values (#4043)
Because I use the Colemak-DH keyboard layout, I have mapped 'i' to 'h'. Therefore, the current mini.ai which_key prompts are inconsistent with my keymap. ## Description The names and prefixes used in mini.ai_whichkey() are hardcoded and should follow the user's mappings. ## Related Issue(s) No ## Screenshots No ## Checklist - [ x ] I've read the [CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md) guidelines. --------- Co-authored-by: Folke Lemaitre <folke.lemaitre@gmail.com>
This commit is contained in:
@ -171,9 +171,6 @@ return {
|
||||
"echasnovski/mini.ai",
|
||||
event = "VeryLazy",
|
||||
opts = function()
|
||||
LazyVim.on_load("which-key.nvim", function()
|
||||
vim.schedule(LazyVim.mini.ai_whichkey)
|
||||
end)
|
||||
local ai = require("mini.ai")
|
||||
return {
|
||||
n_lines = 500,
|
||||
@ -197,6 +194,14 @@ return {
|
||||
},
|
||||
}
|
||||
end,
|
||||
config = function(_, opts)
|
||||
require("mini.ai").setup(opts)
|
||||
LazyVim.on_load("which-key.nvim", function()
|
||||
vim.schedule(function()
|
||||
LazyVim.mini.ai_whichkey(opts)
|
||||
end)
|
||||
end)
|
||||
end,
|
||||
},
|
||||
|
||||
{
|
||||
|
@ -60,7 +60,8 @@ function M.ai_buffer(ai_type)
|
||||
end
|
||||
|
||||
-- register all text objects with which-key
|
||||
function M.ai_whichkey()
|
||||
---@param opts table
|
||||
function M.ai_whichkey(opts)
|
||||
local objects = {
|
||||
{ " ", desc = "whitespace" },
|
||||
{ '"', desc = '" string' },
|
||||
@ -92,14 +93,20 @@ function M.ai_whichkey()
|
||||
}
|
||||
|
||||
local ret = { mode = { "o", "x" } }
|
||||
for prefix, name in pairs({
|
||||
i = "inside",
|
||||
a = "around",
|
||||
il = "last",
|
||||
["in"] = "next",
|
||||
al = "last",
|
||||
an = "next",
|
||||
}) do
|
||||
---@type table<string, string>
|
||||
local mappings = vim.tbl_extend("force", {}, {
|
||||
around = "a",
|
||||
inside = "i",
|
||||
around_next = "an",
|
||||
inside_next = "in",
|
||||
around_last = "al",
|
||||
inside_last = "il",
|
||||
}, opts.mappings or {})
|
||||
mappings.goto_left = nil
|
||||
mappings.goto_right = nil
|
||||
|
||||
for name, prefix in pairs(mappings) do
|
||||
name = name:gsub("^around_", ""):gsub("^inside_", "")
|
||||
ret[#ret + 1] = { prefix, group = name }
|
||||
for _, obj in ipairs(objects) do
|
||||
local desc = obj.desc
|
||||
|
Reference in New Issue
Block a user