From 8506cb5a98a528651a5557d8e447fa13bd8ac0cb Mon Sep 17 00:00:00 2001 From: Johnson Hu Date: Mon, 15 Jul 2024 15:06:34 +0800 Subject: [PATCH] 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 --- lua/lazyvim/plugins/coding.lua | 11 ++++++++--- lua/lazyvim/util/mini.lua | 25 ++++++++++++++++--------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/lua/lazyvim/plugins/coding.lua b/lua/lazyvim/plugins/coding.lua index ffd743b3..e4ce97d2 100644 --- a/lua/lazyvim/plugins/coding.lua +++ b/lua/lazyvim/plugins/coding.lua @@ -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, }, { diff --git a/lua/lazyvim/util/mini.lua b/lua/lazyvim/util/mini.lua index cdb27397..28c069da 100644 --- a/lua/lazyvim/util/mini.lua +++ b/lua/lazyvim/util/mini.lua @@ -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 + 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