From b6e9b175dba521777e2b86979ef80a2eae7a33d6 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Thu, 5 Sep 2013 18:31:33 +1200 Subject: [PATCH] did some math to calcuate offset, now spellcheck only needs to update once :) --- plugins/spellcheck.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/spellcheck.py b/plugins/spellcheck.py index 246f4dd..7af8ab2 100755 --- a/plugins/spellcheck.py +++ b/plugins/spellcheck.py @@ -17,18 +17,20 @@ def spell(inp): chkr = SpellChecker(locale) chkr.set_text(inp) + offset = 0 + for err in chkr: # find the location of the incorrect word - start = err.wordpos + start = err.wordpos + offset finish = start + len(err.word) # get some suggestions for it suggestions = err.suggest() s_string = '/'.join(suggestions[:3]) s_string = "\x02{}\x02".format(s_string) + # calculate the offset for the next word + offset = (offset + len(s_string)) - len(err.word) # replace the word with the suggestions inp = inp[:start] + s_string + inp[finish:] - # reset the text - chkr.set_text(inp) return inp else: