aboutsummaryrefslogtreecommitdiff
path: root/spellcheck.lua
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2020-08-27 15:43:34 +0200
committerFlorian Fischer <florian.fl.fischer@fau.de>2020-08-27 15:43:34 +0200
commit04ab455907fe7da054aeefe05b0be0b534affccd (patch)
tree11ba34ace91f95de134e01ef8c80150402af5353 /spellcheck.lua
parent819f67b78f2bc64f39fc0a48613908c36c674621 (diff)
downloadvis-spellcheck-04ab455907fe7da054aeefe05b0be0b534affccd.tar.gz
vis-spellcheck-04ab455907fe7da054aeefe05b0be0b534affccd.zip
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.
Diffstat (limited to 'spellcheck.lua')
-rw-r--r--spellcheck.lua8
1 files changed, 7 insertions, 1 deletions
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