diff options
author | Florian Fischer <florian.fl.fischer@fau.de> | 2020-08-26 16:30:49 +0200 |
---|---|---|
committer | Florian Fischer <florian.fl.fischer@fau.de> | 2020-08-26 16:30:49 +0200 |
commit | 0d224104468c332b3057c92ff297dfb90d8e35e2 (patch) | |
tree | eed2f0c40d4fcd56af3cbf68fb7d70db5cd8c644 /spellcheck.lua | |
parent | 6de1905b60282d1215dd2eed029295f13877868f (diff) | |
download | vis-spellcheck-0d224104468c332b3057c92ff297dfb90d8e35e2.tar.gz |
change typo_iter to not find typos in correct spelled words
When naivingly searching for the typo in our text we might find it
before its actual appearense in a correct word containing the typo
(e.g. "broken ok" would find the typo "ok" in the middle of the word "broken").
To prevent this we now only find a typo if its enclosed in non-letter
characters, this prevents typos from being found in regular words.
Typos starting with '"' for example are still found correctly.
Diffstat (limited to 'spellcheck.lua')
-rw-r--r-- | spellcheck.lua | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/spellcheck.lua b/spellcheck.lua index 59c5630..fe7d8a3 100644 --- a/spellcheck.lua +++ b/spellcheck.lua @@ -86,9 +86,14 @@ local function typo_iter(text, typos, ignored) until(not typo or not ignored[typo]) if typo then - local start, finish = text:find(typo, index, true) + -- to prevent typos from being found in correct words before them + -- ("stuff stuf", "broken ok", ...) + -- we match typos only when they are enclosed in non-letter characters. + local start, finish = text:find("[%A]" .. typo .. "[%A]", index) index = finish - return typo, start, finish + + -- ignore the first and last non letter character + return typo, start + 1, finish - 1 end end end |