Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(util): only collect valid <> keys #438

Merged
merged 1 commit into from
Apr 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions lua/which-key/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ local Tokens = {
}
---@return KeyCodes
function M.parse_keys(keystr)
local keys = M.t(keystr)
local internal = M.parse_internal(keys)
local notation = {}
---@alias ParseState
--- | "Character"
Expand All @@ -71,7 +73,8 @@ function M.parse_keys(keystr)

if state == "Character" then
start = i
state = c == Tokens["<"] and "Special" or state
-- Only interpret special tokens if neovim also replaces it
state = c == Tokens["<"] and internal[#notation + 1] ~= "<" and "Special" or state
elseif state == "Special" then
state = (c == Tokens["-"] and "SpecialNoClose") or (c == Tokens[">"] and "Character") or state
else
Expand All @@ -85,13 +88,13 @@ function M.parse_keys(keystr)
end
end

local keys = M.t(keystr)
local internal = M.parse_internal(keys)
local mapleader = vim.g.mapleader
mapleader = mapleader and M.t(mapleader)
notation[1] = internal[1] == mapleader and "<leader>" or notation[1]

assert(#notation == #internal, vim.inspect({ internal = internal, notation = notation }))
if #notation ~= #internal then
error(vim.inspect({ internal = internal, notation = notation }))
end

return {
keys = keys,
Expand Down