diff options
| author | Nomarian <nomarian@outlook.com> | 2025-10-09 10:44:41 -0400 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-10-12 21:00:36 +0200 |
| commit | 6f01f568155554778e890368a746815ea034f509 (patch) | |
| tree | 15004c27b25911d872cd3625a9d12f7d2c068647 /spellcheck.lua | |
| parent | 48ab0928587669ff6d5c889df8acdabfd4b29ed0 (diff) | |
| download | vis-spellcheck-6f01f568155554778e890368a746815ea034f509.tar.gz vis-spellcheck-6f01f568155554778e890368a746815ea034f509.zip | |
typo_iter return early instead of having a big if typo then
Diffstat (limited to 'spellcheck.lua')
| -rw-r--r-- | spellcheck.lua | 63 |
1 files changed, 31 insertions, 32 deletions
diff --git a/spellcheck.lua b/spellcheck.lua index c1ce8bc..c0133ae 100644 --- a/spellcheck.lua +++ b/spellcheck.lua @@ -120,41 +120,40 @@ local function typo_iter(text, typos, ignored) -- luacheck: ignore ignored local typo repeat typo = unfiltered_iterator(iter_state) - until (not typo or (typo ~= '' and not ignored[typo])) - - if typo then - 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 occurs 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 - 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 - - 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 + if not typo then return end + until typo ~= '' and not ignored[typo] + + 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 occurs 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 + 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 + + 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 - index = finish - - return typo, start, finish end + index = finish + + return typo, start, finish end end |
