fix(keys): replace term codes to calculate ids

This commit is contained in:
Folke Lemaitre 2023-06-03 13:45:18 +02:00
parent 9223c1aa20
commit d65a3d6755
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
2 changed files with 19 additions and 1 deletions

View File

@ -19,7 +19,7 @@ function M.parse(value)
local ret = vim.deepcopy(value)
ret = type(ret) == "string" and { ret } or ret --[[@as LazyKeys]]
ret.mode = ret.mode or "n"
ret.id = (ret[1] or "")
ret.id = vim.api.nvim_replace_termcodes(ret[1] or "", true, true, true)
if ret.mode then
local mode = ret.mode
if type(mode) == "table" then

View File

@ -0,0 +1,18 @@
local Keys = require("lazy.core.handler.keys")
describe("keys", function()
it("parses ids correctly", function()
local tests = {
{ "<C-/>", "<c-/>", true },
{ "<C-h>", "<c-H>", true },
{ "<C-h>k", "<c-H>K", false },
}
for _, test in ipairs(tests) do
if test[3] then
assert.same(Keys.parse(test[1]).id, Keys.parse(test[2]).id)
else
assert.is_not.same(Keys.parse(test[1]).id, Keys.parse(test[2]).id)
end
end
end)
end)