mirror of
https://github.com/zoriya/lz.n.git
synced 2026-06-01 18:35:18 +00:00
fix(keys): don't ignore modes that aren't 'n' (#28)
* fix(keys): don't ignore modes that aren't `'n'` Fixes #26 * chore(deps): update flake.lock * ci: remove docgen workflow
This commit is contained in:
+31
-17
@@ -2,30 +2,44 @@ local loader = require("lz.n.loader")
|
||||
|
||||
---@class lz.n.KeysHandler: lz.n.Handler
|
||||
|
||||
---@param value lz.n.KeysSpec
|
||||
---@param mode? string
|
||||
---@return lz.n.Keys
|
||||
local function parse(value, mode)
|
||||
local ret = vim.deepcopy(value) --[[@as lz.n.Keys]]
|
||||
ret.lhs = ret[1] or ""
|
||||
ret.rhs = ret[2]
|
||||
ret[1] = nil
|
||||
ret[2] = nil
|
||||
ret.mode = mode or "n"
|
||||
ret.id = vim.api.nvim_replace_termcodes(ret.lhs, true, true, true)
|
||||
if ret.ft then
|
||||
local ft = type(ret.ft) == "string" and { ret.ft } or ret.ft --[[@as string[] ]]
|
||||
ret.id = ret.id .. " (" .. table.concat(ft, ", ") .. ")"
|
||||
end
|
||||
if ret.mode ~= "n" then
|
||||
ret.id = ret.id .. " (" .. ret.mode .. ")"
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
---@type lz.n.KeysHandler
|
||||
local M = {
|
||||
pending = {},
|
||||
spec_field = "keys",
|
||||
---@param value string|lz.n.KeysSpec
|
||||
---@param mode? string
|
||||
---@return lz.n.Keys
|
||||
parse = function(value, mode)
|
||||
---@return lz.n.Keys[]
|
||||
parse = function(value)
|
||||
value = type(value) == "string" and { value } or value --[[@as lz.n.KeysSpec]]
|
||||
local ret = vim.deepcopy(value) --[[@as lz.n.Keys]]
|
||||
ret.lhs = ret[1] or ""
|
||||
ret.rhs = ret[2]
|
||||
ret[1] = nil
|
||||
ret[2] = nil
|
||||
ret.mode = mode or "n"
|
||||
ret.id = vim.api.nvim_replace_termcodes(ret.lhs, true, true, true)
|
||||
if ret.ft then
|
||||
local ft = type(ret.ft) == "string" and { ret.ft } or ret.ft --[[@as string[] ]]
|
||||
ret.id = ret.id .. " (" .. table.concat(ft, ", ") .. ")"
|
||||
local modes = type(value.mode) == "string" and { value.mode } or value.mode --[[ @as string[] | nil ]]
|
||||
if not modes then
|
||||
return { parse(value) }
|
||||
end
|
||||
if ret.mode ~= "n" then
|
||||
ret.id = ret.id .. " (" .. ret.mode .. ")"
|
||||
end
|
||||
return ret
|
||||
return vim.iter(modes)
|
||||
:map(function(mode)
|
||||
return parse(value, mode)
|
||||
end)
|
||||
:totable()
|
||||
end,
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -115,12 +115,12 @@ local function parse(spec)
|
||||
end
|
||||
if type(keys_spec) == "string" then
|
||||
local keys = require("lz.n.handler.keys").parse(keys_spec)
|
||||
table.insert(result.keys, keys)
|
||||
vim.list_extend(result.keys, keys)
|
||||
elseif type(keys_spec) == "table" then
|
||||
---@param keys_spec_ string | lz.n.KeysSpec
|
||||
vim.iter(keys_spec):each(function(keys_spec_)
|
||||
local keys = require("lz.n.handler.keys").parse(keys_spec_)
|
||||
table.insert(result.keys, keys)
|
||||
vim.list_extend(result.keys, keys)
|
||||
end)
|
||||
end
|
||||
local cmd_spec = spec.cmd
|
||||
|
||||
Reference in New Issue
Block a user