Fixes: Spell checker is active for partial words. #166

This commit is contained in:
Olivier Keshavjee 2017-10-19 13:33:36 +02:00
parent eb89d2f309
commit ee058a309f

View file

@ -80,11 +80,21 @@ class basicHighlighter(QSyntaxHighlighter):
fmt)
# Spell checking
# Following algorithm would not check words at the end of line.
# This hacks adds a space to every line where the text cursor is not
# So that it doesn't spellcheck while typing, but still spellchecks at
# end of lines. See github's issue #166.
textedText = text
if self.currentBlock().position() + len(text) != \
self.editor.textCursor().position():
textedText = text + " "
# Based on http://john.nachtimwald.com/2009/08/22/qplaintextedit-with-in-line-spell-check/
WORDS = '(?iu)[\w\']+'
WORDS = '(?iu)([\w\']+)\W' # (?iu) means case insensitive and unicode
if hasattr(self.editor, "spellcheck") and self.editor.spellcheck:
for word_object in re.finditer(WORDS, text):
if self.editor._dict and not self.editor._dict.check(word_object.group()):
for word_object in re.finditer(WORDS, textedText):
if self.editor._dict and not self.editor._dict.check(word_object.group(1)):
format = self.format(word_object.start())
format.setUnderlineColor(self._misspelledColor)
# SpellCheckUnderline fails with some fonts