From c0eef2f85a44e4bbaac1af27f428dfd22ebd06ab Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Thu, 27 Aug 2020 14:10:09 +0200 Subject: fix highlighting of typos at the end of the text Our pattern [%A][%A] does not match typos at the end or start of the text because there is no leading / trailing non letter character. So if we dind't find the typo with our normal pattern it must be either the start or the end of the text. If not raise a warning that this must be a bug. --- spellcheck.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'spellcheck.lua') diff --git a/spellcheck.lua b/spellcheck.lua index 782fe8f..89d2bd7 100644 --- a/spellcheck.lua +++ b/spellcheck.lua @@ -91,6 +91,13 @@ local function typo_iter(text, typos, ignored) -- ("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) + -- the typo was not found by our pattern this means it must be the last word in the text + if not start then + start, finish = text:find("[%A]" .. typo .. "$", index) + if not start then + vis:info(string.format("typo %s not found after %d this must be a bug please report", typo, index)) + end + end index = finish -- ignore the first and last non letter character -- cgit v1.2.3