Merge pull request #1214 from TheShadowblast123/develop

Update spellchecker.py And Fixed crashing
This commit is contained in:
Tobias Frisch 2023-12-07 16:06:03 +01:00 committed by GitHub
commit 3d4eef2b49
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 3 deletions

View file

@ -187,6 +187,7 @@ class BasicDictionary:
def checkText(self, text):
# Based on http://john.nachtimwald.com/2009/08/22/qplaintextedit-with-in-line-spell-check/
WORDS = r'(?iu)((?:[^_\W]|\')+)[^A-Za-z0-9\']'
# (?iu) means case insensitive and Unicode
# ((?:[^_\W]|\')+) means words exclude underscores but include apostrophes
# [^A-Za-z0-9\'] used with above hack to prevent spellcheck while typing word
@ -197,8 +198,27 @@ class BasicDictionary:
for word_object in re.finditer(WORDS, text):
word = word_object.group(1)
mispelled = self.isMisspelled(word)
if mispelled == False:
continue
#inorder to prevent apostrophes causing false positives and keep the same functionality otherwise,
#check that the word doesn't have any additional punctuation on it.
if re.match("^[^\w]|([\p{P}'])$", word):
# ^[^\w] checks that it doesn't start with a word character
# ([\p{P}'])$ checks it doesn't end with punctuation characters
apostrophe_WORDS = r'(?iu)\b(?<=[\s\'"(])((?:[a-zA-Z]|\')+)(?=\b)'
# \b(?<=[\s\'"(]) looks for nonword characters and starts grouping after
# (?=\b) looks for the word boundary
# ((?:[a-zA-Z]|\')+) greedily matches for letters and apostrophes
temp = re.match(apostrophe_WORDS, word)
mispelled = self.isMisspelled(temp.group(1))
if (mispelled and not self.isCustomWord(word)):
if (self.isMisspelled(word) and not self.isCustomWord(word)):
matches.append(BasicMatch(
word_object.start(1), word_object.end(1)
))

View file

@ -384,7 +384,12 @@ class corkDelegate(QStyledItemDelegate):
# Draw Summary
# One line
if lineSummary:
#checking that textColor is actually defined before we use it
try:
textColor
except:
textColor = None
if lineSummary and textColor:
p.save()
f = QFont(option.font)
f.setBold(True)
@ -396,7 +401,7 @@ class corkDelegate(QStyledItemDelegate):
p.restore()
# Full summary
if fullSummary:
if fullSummary and textColor:
p.save()
p.setFont(option.font)
p.setPen(textColor)