From 4814509d70b19e0c8e0118c8175bb7dc89de493b Mon Sep 17 00:00:00 2001 From: manuuurino <2855338+manuuurino@users.noreply.github.com> Date: Tue, 9 Apr 2024 21:16:17 +0200 Subject: [PATCH 1/3] feat(editing-support): add `mini-operators` --- .../editing-support/mini-operators/README.md | 5 +++ .../editing-support/mini-operators/init.lua | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 lua/astrocommunity/editing-support/mini-operators/README.md create mode 100644 lua/astrocommunity/editing-support/mini-operators/init.lua diff --git a/lua/astrocommunity/editing-support/mini-operators/README.md b/lua/astrocommunity/editing-support/mini-operators/README.md new file mode 100644 index 000000000..af194555e --- /dev/null +++ b/lua/astrocommunity/editing-support/mini-operators/README.md @@ -0,0 +1,5 @@ +# mini-operators + +Text edit operators. Part of 'mini.nvim' library. + +**Repository:** diff --git a/lua/astrocommunity/editing-support/mini-operators/init.lua b/lua/astrocommunity/editing-support/mini-operators/init.lua new file mode 100644 index 000000000..3eb0aba0d --- /dev/null +++ b/lua/astrocommunity/editing-support/mini-operators/init.lua @@ -0,0 +1,31 @@ +-- NOTE: this will override the default AstroNvim keybinding for opening neo-tree. +-- the default prefix would be g, but this will also override some bindings. +local prefix = "o" + +local mappings = { + n = { + [prefix] = { + name = "Text edit operators", + }, + }, +} + +---@type LazySpec +return { + "echasnovski/mini.operators", + event = "User AstroFile", + dependencies = { + "AstroNvim/astrocore", + ---@type AstroCoreOpts + opts = { + mappings = mappings, + }, + }, + opts = { + evaluate = { prefix = prefix .. "e" }, + exchange = { prefix = prefix .. "x" }, + multiply = { prefix = prefix .. "m" }, + replace = { prefix = prefix .. "r" }, + sort = { prefix = prefix .. "s" }, + }, +} From 378fb76fa832ada3878578099c166717582f135c Mon Sep 17 00:00:00 2001 From: manuuurino <2855338+manuuurino@users.noreply.github.com> Date: Wed, 10 Apr 2024 22:39:53 +0200 Subject: [PATCH 2/3] fix(mini-operators): add missing header for visual and changed prefix to default --- .../editing-support/mini-operators/init.lua | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lua/astrocommunity/editing-support/mini-operators/init.lua b/lua/astrocommunity/editing-support/mini-operators/init.lua index 3eb0aba0d..4f3fc298c 100644 --- a/lua/astrocommunity/editing-support/mini-operators/init.lua +++ b/lua/astrocommunity/editing-support/mini-operators/init.lua @@ -1,14 +1,5 @@ --- NOTE: this will override the default AstroNvim keybinding for opening neo-tree. --- the default prefix would be g, but this will also override some bindings. -local prefix = "o" - -local mappings = { - n = { - [prefix] = { - name = "Text edit operators", - }, - }, -} +-- NOTE: the default prefix is `g`, but this will override some bindings. +local prefix = "g" ---@type LazySpec return { @@ -18,7 +9,18 @@ return { "AstroNvim/astrocore", ---@type AstroCoreOpts opts = { - mappings = mappings, + mappings = { + n = { + [prefix] = { + name = "Text edit operators", + }, + }, + v = { + [prefix] = { + name = "Text edit operators", + }, + }, + }, }, }, opts = { From 9f17c9b30f4a6f6d4c90a5aa7699857ccaeb7a66 Mon Sep 17 00:00:00 2001 From: Micah Halter Date: Thu, 11 Apr 2024 16:43:55 -0400 Subject: [PATCH 3/3] fix(mini-operators): correctly implement `keys` lazy loading --- .../editing-support/mini-operators/init.lua | 50 ++++++++----------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/lua/astrocommunity/editing-support/mini-operators/init.lua b/lua/astrocommunity/editing-support/mini-operators/init.lua index 4f3fc298c..5b7c1562a 100644 --- a/lua/astrocommunity/editing-support/mini-operators/init.lua +++ b/lua/astrocommunity/editing-support/mini-operators/init.lua @@ -1,33 +1,25 @@ --- 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(_, keys) + local plugin = require("lazy.core.config").spec.plugins["mini.operators"] + local opts = require("lazy.core.plugin").values(plugin, "opts", false) + 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(keys, { + { line_lhs, desc = name .. " line" }, + { prefix, desc = name .. " operator" }, + { prefix, mode = "x", desc = name .. " selection" }, + }) + end + end, + opts = {}, }