aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Fischer <gitlab@muhq.space>2023-03-02 16:26:37 +0000
committerFlorian Fischer <gitlab@muhq.space>2023-03-02 16:26:37 +0000
commit0e6c04945b6ce920bbd074e61949de62f1b41763 (patch)
treedf4b810fd722aeef12c65e5a28276b7cce974b6b
parent40f20dfde4a5702b0b02b2d89ad746a93d851c27 (diff)
parent870fe9f83d2105dc5025f0b2895112c1d5466f13 (diff)
downloadvis-spellcheck-0e6c04945b6ce920bbd074e61949de62f1b41763.tar.gz
Merge branch 'fix-leading-typo-detection' into 'master'
fix typo detection at file start See merge request muhq/vis-spellcheck!11
-rw-r--r--spellcheck.lua37
1 files changed, 19 insertions, 18 deletions
diff --git a/spellcheck.lua b/spellcheck.lua
index a8dd37d..1d0d6c7 100644
--- a/spellcheck.lua
+++ b/spellcheck.lua
@@ -125,32 +125,33 @@ local function typo_iter(text, typos, ignored) -- luacheck: ignore ignored
until (not typo or (typo ~= '' and not ignored[typo]))
if typo then
- -- 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]' .. escape_lua_pattern(typo) ..
- '[%A]', index)
- -- typo was not found by our pattern this means it must be either
- -- the first or last word in the text
- if not start then
- -- check start of text
+ local start, finish
+ -- special case for typos at the beginning of the text
+ -- Leading typos are not found by our used pattern [%A]typo[%A].
+ -- To prevent typos to be skipped if the leading typo accours an
+ -- additional time in the text we need this special case
+ if index == 1 and text:sub(1, #typo) == typo then
start = 1
finish = #typo
- -- typo is not the beginning must be the end of text
- if text:sub(start, finish) ~= typo then
+ else
+ -- 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 pattern = '[%A]' .. escape_lua_pattern(typo) .. '[%A]'
+ start, finish = text:find(pattern, index)
+ if start then -- our pattern [%A]typo[%A] found it
+ start = start + 1 -- ignore leading non letter char
+ finish = finish - 1 -- ignore trailing non letter char
+ else -- typo was not found by our pattern this means it must be the last word
start = #text - #typo + 1
finish = start + #typo - 1
- end
- if text:sub(start, finish) ~= typo then
- vis:info(string.format(
+ if text:sub(start, finish) ~= typo then
+ vis:info(string.format(
'can\'t find typo %s after %d. Please report this bug.',
typo, index))
+ end
end
- -- our pettern [%A]typo[%A] found it
- else
- start = start + 1 -- ignore leading non letter char
- finish = finish - 1 -- ignore trailing non letter char
end
index = finish