aboutsummaryrefslogtreecommitdiffstats
path: root/spellcheck.lua
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2020-08-26 16:30:49 +0200
committerFlorian Fischer <florian.fl.fischer@fau.de>2020-08-26 16:30:49 +0200
commit0d224104468c332b3057c92ff297dfb90d8e35e2 (patch)
treeeed2f0c40d4fcd56af3cbf68fb7d70db5cd8c644 /spellcheck.lua
parent6de1905b60282d1215dd2eed029295f13877868f (diff)
downloadvis-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.lua9
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