Skip to content

Commit

Permalink
Merge pull request #1214 from TheShadowblast123/develop
Browse files Browse the repository at this point in the history
Update spellchecker.py And Fixed crashing
  • Loading branch information
TheJackiMonster committed Dec 7, 2023
2 parents 1fd8762 + 1612906 commit 3d4eef2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
22 changes: 21 additions & 1 deletion manuskript/functions/spellchecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def availableDictionaries():
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
Expand All @@ -197,8 +198,27 @@ def checkText(self, text):

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)
))
Expand Down
9 changes: 7 additions & 2 deletions manuskript/ui/views/corkDelegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,12 @@ def drawRect(r):

# 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)
Expand All @@ -396,7 +401,7 @@ def drawRect(r):
p.restore()

# Full summary
if fullSummary:
if fullSummary and textColor:
p.save()
p.setFont(option.font)
p.setPen(textColor)
Expand Down

0 comments on commit 3d4eef2

Please sign in to comment.