did some math to calcuate offset, now spellcheck only needs to update once :)
This commit is contained in:
parent
033dd8af12
commit
b6e9b175db
1 changed files with 5 additions and 3 deletions
|
@ -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:
|
||||
|
|
Reference in a new issue