mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-06-29 03:44:14 +00:00
Merge remote-tracking branch 'upstream/main' into feat/prioritize-cond
This commit is contained in:
commit
7e39270651
27 changed files with 1212 additions and 905 deletions
|
@ -14,16 +14,22 @@ end
|
|||
---@param cmd string
|
||||
function M:_add(cmd)
|
||||
vim.api.nvim_create_user_command(cmd, function(event)
|
||||
local command = {
|
||||
cmd = cmd,
|
||||
bang = event.bang or nil,
|
||||
mods = event.smods,
|
||||
args = event.fargs,
|
||||
count = event.count >= 0 and event.range == 0 and event.count or nil,
|
||||
}
|
||||
|
||||
if event.range == 1 then
|
||||
command.range = { event.line1 }
|
||||
elseif event.range == 2 then
|
||||
command.range = { event.line1, event.line2 }
|
||||
end
|
||||
|
||||
self:_load(cmd)
|
||||
vim.cmd(
|
||||
("%s %s%s%s %s"):format(
|
||||
event.mods or "",
|
||||
event.line1 == event.line2 and "" or event.line1 .. "," .. event.line2,
|
||||
cmd,
|
||||
event.bang and "!" or "",
|
||||
event.args or ""
|
||||
)
|
||||
)
|
||||
vim.cmd(command)
|
||||
end, {
|
||||
bang = true,
|
||||
range = true,
|
||||
|
|
|
@ -3,7 +3,7 @@ local Loader = require("lazy.core.loader")
|
|||
|
||||
---@class LazyKeys
|
||||
---@field [1] string lhs
|
||||
---@field [2]? string|fun() rhs
|
||||
---@field [2]? string|fun()|false rhs
|
||||
---@field desc? string
|
||||
---@field mode? string|string[]
|
||||
---@field noremap? boolean
|
||||
|
@ -14,42 +14,6 @@ local Loader = require("lazy.core.loader")
|
|||
---@class LazyKeysHandler:LazyHandler
|
||||
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
|
||||
function M.parse(value)
|
||||
local ret = vim.deepcopy(value)
|
||||
|
@ -108,9 +72,16 @@ function M:_add(keys)
|
|||
|
||||
Util.track({ keys = lhs })
|
||||
Loader.load(plugins, { keys = lhs })
|
||||
M.retrigger(lhs)
|
||||
Util.track()
|
||||
end, opts)
|
||||
|
||||
local feed = vim.api.nvim_replace_termcodes("<Ignore>" .. lhs, true, true, true)
|
||||
-- insert instead of append the lhs
|
||||
vim.api.nvim_feedkeys(feed, "i", false)
|
||||
end, {
|
||||
desc = opts.desc,
|
||||
-- we do not return anything, but this is still needed to make operator pending mappings work
|
||||
expr = true,
|
||||
})
|
||||
end
|
||||
|
||||
---@param keys LazyKeys
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue