Skip to content

Commit

Permalink
fix: better handling of weird norm and getchar endless <esc> bug #68
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed May 13, 2021
1 parent 9d2785c commit bfd37e9
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions lua/which-key/view.lua
Expand Up @@ -50,25 +50,35 @@ function M.show()
end

function M.read_pending()
local esc = ""
while true do
local n = vim.fn.getchar(0)
if n == 0 then
return
end
local c = (type(n) == "number" and vim.fn.nr2char(n) or n)

-- for some reason, when executing a :norm command,
-- vim keeps feeding <esc> at the end
if c == Util.t("<esc>") then
return
end

-- Fix < characters
if c == "<" then
c = "<lt>"
end

M.keys = M.keys .. c
-- HACK: for some reason, when executing a :norm command,
-- vim keeps feeding <esc> at the end
if c == Util.t("<esc>") then
esc = esc .. c
-- more than 10 <esc> in a row? most likely the norm bug
if #esc > 10 then
return
end
else
-- we have <esc> characters, so add them to keys
if esc ~= "" then
M.keys = M.keys .. esc
esc = ""
end
M.keys = M.keys .. c
end
end
end

Expand Down

0 comments on commit bfd37e9

Please sign in to comment.