mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-09-29 08:51:14 +13:00
Fixes: Spell checker is active for partial words. #166
This commit is contained in:
parent
eb89d2f309
commit
ee058a309f
1 changed files with 13 additions and 3 deletions
|
@ -80,11 +80,21 @@ class basicHighlighter(QSyntaxHighlighter):
|
||||||
fmt)
|
fmt)
|
||||||
|
|
||||||
# Spell checking
|
# 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/
|
# 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:
|
if hasattr(self.editor, "spellcheck") and self.editor.spellcheck:
|
||||||
for word_object in re.finditer(WORDS, text):
|
for word_object in re.finditer(WORDS, textedText):
|
||||||
if self.editor._dict and not self.editor._dict.check(word_object.group()):
|
if self.editor._dict and not self.editor._dict.check(word_object.group(1)):
|
||||||
format = self.format(word_object.start())
|
format = self.format(word_object.start())
|
||||||
format.setUnderlineColor(self._misspelledColor)
|
format.setUnderlineColor(self._misspelledColor)
|
||||||
# SpellCheckUnderline fails with some fonts
|
# SpellCheckUnderline fails with some fonts
|
||||||
|
|
Loading…
Reference in a new issue