mirror of https://github.com/folke/lazy.nvim.git
fix(keys): refactor retrigger mechanism (#428)
* fix keymap retrigger in operator mode * remove unnecessary retrigger logic we can just eval `"<Ignore>" .. lhs` to retrigger the mapping * remove unused function --------- Co-authored-by: MurdeRM3L0DY <>
This commit is contained in:
parent
57a3960faf
commit
4272d2100a
|
@ -14,42 +14,6 @@ local Loader = require("lazy.core.loader")
|
||||||
---@class LazyKeysHandler:LazyHandler
|
---@class LazyKeysHandler:LazyHandler
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
---@param feed string
|
|
||||||
function M.replace_special(feed)
|
|
||||||
for special, key in pairs({ leader = vim.g.mapleader or "\\", localleader = vim.g.maplocalleader or "\\" }) do
|
|
||||||
local pattern = "<"
|
|
||||||
for i = 1, #special do
|
|
||||||
pattern = pattern .. "[" .. special:sub(i, i) .. special:upper():sub(i, i) .. "]"
|
|
||||||
end
|
|
||||||
pattern = pattern .. ">"
|
|
||||||
feed = feed:gsub(pattern, key)
|
|
||||||
end
|
|
||||||
return feed
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.retrigger(keys)
|
|
||||||
local pending = ""
|
|
||||||
while true do
|
|
||||||
---@type number|string
|
|
||||||
local c = vim.fn.getchar(0)
|
|
||||||
if c == 0 then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
c = type(c) == "number" and vim.fn.nr2char(c) or c
|
|
||||||
pending = pending .. c
|
|
||||||
end
|
|
||||||
local op = vim.v.operator
|
|
||||||
if op and op ~= "" and vim.api.nvim_get_mode().mode:find("o") then
|
|
||||||
keys = "<esc>" .. op .. keys
|
|
||||||
end
|
|
||||||
local feed = keys .. pending
|
|
||||||
feed = M.replace_special(feed)
|
|
||||||
if vim.v.count ~= 0 then
|
|
||||||
feed = vim.v.count .. feed
|
|
||||||
end
|
|
||||||
vim.api.nvim_input(feed)
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param value string|LazyKeys
|
---@param value string|LazyKeys
|
||||||
function M.parse(value)
|
function M.parse(value)
|
||||||
local ret = vim.deepcopy(value)
|
local ret = vim.deepcopy(value)
|
||||||
|
@ -99,6 +63,8 @@ end
|
||||||
function M:_add(keys)
|
function M:_add(keys)
|
||||||
local lhs = keys[1]
|
local lhs = keys[1]
|
||||||
local opts = M.opts(keys)
|
local opts = M.opts(keys)
|
||||||
|
opts.remap = true
|
||||||
|
opts.expr = true
|
||||||
vim.keymap.set(keys.mode, lhs, function()
|
vim.keymap.set(keys.mode, lhs, function()
|
||||||
local plugins = self.active[keys.id]
|
local plugins = self.active[keys.id]
|
||||||
|
|
||||||
|
@ -108,8 +74,9 @@ function M:_add(keys)
|
||||||
|
|
||||||
Util.track({ keys = lhs })
|
Util.track({ keys = lhs })
|
||||||
Loader.load(plugins, { keys = lhs })
|
Loader.load(plugins, { keys = lhs })
|
||||||
M.retrigger(lhs)
|
|
||||||
Util.track()
|
Util.track()
|
||||||
|
|
||||||
|
return "<Ignore>" .. lhs
|
||||||
end, opts)
|
end, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue