Skip to content

Commit

Permalink
fix(mini-operators): correctly implemente keys lazy loading
Browse files Browse the repository at this point in the history
  • Loading branch information
mehalter committed Apr 11, 2024
1 parent 378fb76 commit 8328f16
Showing 1 changed file with 23 additions and 29 deletions.
52 changes: 23 additions & 29 deletions lua/astrocommunity/editing-support/mini-operators/init.lua
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
-- NOTE: the default prefix is `g`, but this will override some bindings.
local prefix = "g"

---@type LazySpec
return {
"echasnovski/mini.operators",
event = "User AstroFile",
dependencies = {
"AstroNvim/astrocore",
---@type AstroCoreOpts
opts = {
mappings = {
n = {
[prefix] = {
name = "Text edit operators",
},
},
v = {
[prefix] = {
name = "Text edit operators",
},
},
},
},
},
opts = {
evaluate = { prefix = prefix .. "e" },
exchange = { prefix = prefix .. "x" },
multiply = { prefix = prefix .. "m" },
replace = { prefix = prefix .. "r" },
sort = { prefix = prefix .. "s" },
},
keys = function()
local plugin = require("lazy.core.config").spec.plugins["mini.operators"]
local opts = require("lazy.core.plugin").values(plugin, "opts", false)
local maps = {}
for operator, default in pairs {
evaluate = "g=",
exchange = "gx",
multiply = "gm",
replace = "gr",
sort = "gs",
} do
local prefix = vim.tbl_get(opts, operator, "prefix") or default
local line_lhs = prefix .. vim.fn.strcharpart(prefix, vim.fn.strchars(prefix) - 1, 1)
local name = operator:sub(1, 1):upper() .. operator:sub(2)
vim.list_extend(maps, {
{ line_lhs, desc = name .. " line" },
{ prefix, desc = name .. " operator" },
{ prefix, mode = "x", desc = name .. " selection" },
})
end
return maps
end,
opts = {},
}

0 comments on commit 8328f16

Please sign in to comment.