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:
Johnson Hu
2024-07-15 15:06:34 +08:00
committed by GitHub
parent e80ed322a7
commit 8506cb5a98
2 changed files with 24 additions and 12 deletions

View File

@ -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,
},
{

View File

@ -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