From 04ab455907fe7da054aeefe05b0be0b534affccd Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Thu, 27 Aug 2020 15:43:34 +0200 Subject: don't loop infinitely if a typo spans multiple tokens This happens because the "default" token gets emitted for each not matched char resulting in lots of small "default" tokens. This markdown: > typu will result in the token stream {"default", 2, "default", 3, "default", 4, "default", 5} and a typo stream with a single entry spanning all of the tokens {{"typu", 1, 5}}. Not checking if the typo is longer then the current token leads to an infinite loop where the typo is always inserted in the new token stream without advancing the token stream. --- spellcheck.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'spellcheck.lua') diff --git a/spellcheck.lua b/spellcheck.lua index 0627d4d..ebfe660 100644 --- a/spellcheck.lua +++ b/spellcheck.lua @@ -203,7 +203,13 @@ local wrap_lex_func = function(old_lex_func) -- highlight typo table.insert(new_tokens, vis.lexers.ERROR) - table.insert(new_tokens, typo_end + 1) + -- the typo spans multiple tokens + if token_end < typo_end then + table.insert(new_tokens, token_end + 1) + i = i + 2 + else + table.insert(new_tokens, typo_end + 1) + end end until(not token_end or token_end >= typo_end) end -- cgit v1.2.3