Merge pull request #141 from vkbo/spell_highlight_fix
Spell Check Fixes
This commit is contained in:
@@ -53,6 +53,7 @@ class GuiDocEditor(QTextEdit):
|
|||||||
self.wordCount = 0
|
self.wordCount = 0
|
||||||
self.paraCount = 0
|
self.paraCount = 0
|
||||||
self.lastEdit = 0
|
self.lastEdit = 0
|
||||||
|
self.nonWord = "\"'"
|
||||||
|
|
||||||
# Typography
|
# Typography
|
||||||
self.typDQOpen = self.mainConf.fmtDoubleQuotes[0]
|
self.typDQOpen = self.mainConf.fmtDoubleQuotes[0]
|
||||||
@@ -137,6 +138,11 @@ class GuiDocEditor(QTextEdit):
|
|||||||
created, and when the user changes the main editor preferences.
|
created, and when the user changes the main editor preferences.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Some Constants
|
||||||
|
self.nonWord = "\"'"
|
||||||
|
self.nonWord += "".join(self.mainConf.fmtDoubleQuotes)
|
||||||
|
self.nonWord += "".join(self.mainConf.fmtSingleQuotes)
|
||||||
|
|
||||||
# Reload spell check and dictionaries
|
# Reload spell check and dictionaries
|
||||||
self._setupSpellChecking()
|
self._setupSpellChecking()
|
||||||
self.setDictionaries()
|
self.setDictionaries()
|
||||||
@@ -500,7 +506,7 @@ class GuiDocEditor(QTextEdit):
|
|||||||
|
|
||||||
theCursor = self.cursorForPosition(thePos)
|
theCursor = self.cursorForPosition(thePos)
|
||||||
theCursor.select(QTextCursor.WordUnderCursor)
|
theCursor.select(QTextCursor.WordUnderCursor)
|
||||||
theWord = theCursor.selectedText()
|
theWord = theCursor.selectedText().strip().strip(self.nonWord)
|
||||||
if theWord == "":
|
if theWord == "":
|
||||||
return
|
return
|
||||||
if self.theDict.checkWord(theWord):
|
if self.theDict.checkWord(theWord):
|
||||||
@@ -541,7 +547,7 @@ class GuiDocEditor(QTextEdit):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def _addWord(self, theCursor):
|
def _addWord(self, theCursor):
|
||||||
theWord = theCursor.selectedText().strip()
|
theWord = theCursor.selectedText().strip().strip(self.nonWord)
|
||||||
logger.debug("Added '%s' to project dictionary" % theWord)
|
logger.debug("Added '%s' to project dictionary" % theWord)
|
||||||
self.theDict.addWord(theWord)
|
self.theDict.addWord(theWord)
|
||||||
self.hLight.setDict(self.theDict)
|
self.hLight.setDict(self.theDict)
|
||||||
|
|||||||
@@ -202,7 +202,11 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
|||||||
))
|
))
|
||||||
|
|
||||||
# Build a QRegExp for each pattern and for the spell checker
|
# Build a QRegExp for each pattern and for the spell checker
|
||||||
self.rules = [(QRegularExpression(a),b) for (a,b) in self.hRules]
|
self.rxRules = []
|
||||||
|
for regEx, regRules in self.hRules:
|
||||||
|
hReg = QRegularExpression(regEx)
|
||||||
|
hReg.setPatternOptions(QRegularExpression.UseUnicodePropertiesOption)
|
||||||
|
self.rxRules.append((hReg, regRules))
|
||||||
self.spellRx = QRegularExpression(r"\b[^\s]+\b")
|
self.spellRx = QRegularExpression(r"\b[^\s]+\b")
|
||||||
self.spellRx.setPatternOptions(QRegularExpression.UseUnicodePropertiesOption)
|
self.spellRx.setPatternOptions(QRegularExpression.UseUnicodePropertiesOption)
|
||||||
|
|
||||||
@@ -253,9 +257,12 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
|||||||
kwFmt.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline)
|
kwFmt.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline)
|
||||||
self.setFormat(xPos, xLen, kwFmt)
|
self.setFormat(xPos, xLen, kwFmt)
|
||||||
|
|
||||||
|
# We're done, no need to continue
|
||||||
|
return
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Other text just uses regex
|
# For other text, just use our regex rules
|
||||||
for rX, xFmt in self.rules:
|
for rX, xFmt in self.rxRules:
|
||||||
rxItt = rX.globalMatch(theText, 0)
|
rxItt = rX.globalMatch(theText, 0)
|
||||||
while rxItt.hasNext():
|
while rxItt.hasNext():
|
||||||
rxMatch = rxItt.next()
|
rxMatch = rxItt.next()
|
||||||
@@ -264,10 +271,10 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
|||||||
xLen = rxMatch.capturedLength(xM)
|
xLen = rxMatch.capturedLength(xM)
|
||||||
self.setFormat(xPos, xLen, xFmt[xM])
|
self.setFormat(xPos, xLen, xFmt[xM])
|
||||||
|
|
||||||
if self.theDict is None or not self.spellCheck or theText.startswith("@"):
|
if self.theDict is None or not self.spellCheck:
|
||||||
return
|
return
|
||||||
|
|
||||||
rxSpell = self.spellRx.globalMatch(theText.replace("_"," "), 0)
|
rxSpell = self.spellRx.globalMatch(theText, 0)
|
||||||
while rxSpell.hasNext():
|
while rxSpell.hasNext():
|
||||||
rxMatch = rxSpell.next()
|
rxMatch = rxSpell.next()
|
||||||
if not self.theDict.checkWord(rxMatch.captured(0)):
|
if not self.theDict.checkWord(rxMatch.captured(0)):
|
||||||
|
|||||||
@@ -173,6 +173,7 @@ class GuiMain(QMainWindow):
|
|||||||
self.asDocTimer.start()
|
self.asDocTimer.start()
|
||||||
self.statusBar.clearStatus()
|
self.statusBar.clearStatus()
|
||||||
|
|
||||||
|
self.showNormal()
|
||||||
if self.mainConf.isFullScreen:
|
if self.mainConf.isFullScreen:
|
||||||
self.toggleFullScreenMode()
|
self.toggleFullScreenMode()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user