fix(keys): only replace localleader and maplocalleader. Fixes #307, fixes #308

This commit is contained in:
Folke Lemaitre 2023-01-04 07:54:35 +01:00
parent a11a317a92
commit 507b695753
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 16 additions and 1 deletions

View File

@ -13,6 +13,19 @@ 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, localleader = vim.g.maplocalleader }) 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) function M.retrigger(keys)
local pending = "" local pending = ""
while true do while true do
@ -28,10 +41,12 @@ function M.retrigger(keys)
if op and op ~= "" and vim.api.nvim_get_mode().mode:find("o") then if op and op ~= "" and vim.api.nvim_get_mode().mode:find("o") then
keys = "<esc>" .. op .. keys keys = "<esc>" .. op .. keys
end end
local feed = vim.api.nvim_replace_termcodes(keys, true, true, true) .. pending local feed = keys .. pending
feed = M.replace_special(feed)
if vim.v.count ~= 0 then if vim.v.count ~= 0 then
feed = vim.v.count .. feed feed = vim.v.count .. feed
end end
vim.notify(feed)
vim.api.nvim_input(feed) vim.api.nvim_input(feed)
end end