Improved highlighter performance and disabled initial spell checking
This commit is contained in:
@@ -214,7 +214,14 @@ class GuiDocEditor(QTextEdit):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
self.hLight.setHandle(tHandle)
|
self.hLight.setHandle(tHandle)
|
||||||
|
spTemp = self.hLight.spellCheck
|
||||||
|
self.hLight.spellCheck = False
|
||||||
|
|
||||||
|
bfTime = time()
|
||||||
self.setPlainText(theDoc)
|
self.setPlainText(theDoc)
|
||||||
|
afTime = time()
|
||||||
|
logger.debug("Document highlighted in %.3f milliseconds" % (1000*(afTime-bfTime)))
|
||||||
|
|
||||||
self.setCursorPosition(self.nwDocument.theItem.cursorPos)
|
self.setCursorPosition(self.nwDocument.theItem.cursorPos)
|
||||||
self.lastEdit = time()
|
self.lastEdit = time()
|
||||||
self._runCounter()
|
self._runCounter()
|
||||||
@@ -227,6 +234,8 @@ class GuiDocEditor(QTextEdit):
|
|||||||
else:
|
else:
|
||||||
self.theParent.noticeBar.showNote("This document is read only.")
|
self.theParent.noticeBar.showNote("This document is read only.")
|
||||||
|
|
||||||
|
self.hLight.spellCheck = spTemp
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def replaceText(self, theText):
|
def replaceText(self, theText):
|
||||||
|
|||||||
@@ -101,47 +101,7 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
|||||||
"value" : self._makeFormat(self.colVal),
|
"value" : self._makeFormat(self.colVal),
|
||||||
}
|
}
|
||||||
|
|
||||||
# Headers
|
|
||||||
self.hRules = []
|
self.hRules = []
|
||||||
self.hRules.append((
|
|
||||||
r"^(#{1}) (.*)[^\n]", {
|
|
||||||
0 : self.hStyles["header1"],
|
|
||||||
1 : self.hStyles["header1h"],
|
|
||||||
}
|
|
||||||
))
|
|
||||||
self.hRules.append((
|
|
||||||
r"^(#{2}) (.*)[^\n]", {
|
|
||||||
0 : self.hStyles["header2"],
|
|
||||||
1 : self.hStyles["header2h"],
|
|
||||||
}
|
|
||||||
))
|
|
||||||
self.hRules.append((
|
|
||||||
r"^(#{3}) (.*)[^\n]", {
|
|
||||||
0 : self.hStyles["header3"],
|
|
||||||
1 : self.hStyles["header3h"],
|
|
||||||
}
|
|
||||||
))
|
|
||||||
self.hRules.append((
|
|
||||||
r"^(#{4}) (.*)[^\n]", {
|
|
||||||
0 : self.hStyles["header4"],
|
|
||||||
1 : self.hStyles["header4h"],
|
|
||||||
}
|
|
||||||
))
|
|
||||||
|
|
||||||
# Keyword/Value
|
|
||||||
# self.hRules.append((
|
|
||||||
# r"^(@.+?)\s*:\s*(.+?)$", {
|
|
||||||
# 1 : self.hStyles["keyword"],
|
|
||||||
# 2 : self.hStyles["value"],
|
|
||||||
# }
|
|
||||||
# ))
|
|
||||||
|
|
||||||
# Comments
|
|
||||||
self.hRules.append((
|
|
||||||
r"^%.*$", {
|
|
||||||
0 : self.hStyles["hidden"],
|
|
||||||
}
|
|
||||||
))
|
|
||||||
|
|
||||||
# Trailing Spaces, 2+
|
# Trailing Spaces, 2+
|
||||||
self.hRules.append((
|
self.hRules.append((
|
||||||
@@ -242,11 +202,10 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
|||||||
|
|
||||||
def highlightBlock(self, theText):
|
def highlightBlock(self, theText):
|
||||||
|
|
||||||
if self.theHandle is None:
|
if self.theHandle is None or not theText:
|
||||||
return
|
return
|
||||||
|
|
||||||
if theText.startswith("@"):
|
if theText.startswith("@"): # Keywords and commands
|
||||||
# Highlighting of keywords and commands
|
|
||||||
tItem = self.theParent.theProject.getItem(self.theHandle)
|
tItem = self.theParent.theProject.getItem(self.theHandle)
|
||||||
isValid, theBits, thePos = self.theIndex.scanThis(theText)
|
isValid, theBits, thePos = self.theIndex.scanThis(theText)
|
||||||
isGood = self.theIndex.checkThese(theBits, tItem)
|
isGood = self.theIndex.checkThese(theBits, tItem)
|
||||||
@@ -265,11 +224,26 @@ 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
|
elif theText.startswith("# "): # Header 1
|
||||||
return
|
self.setFormat(0, 1, self.hStyles["header1"])
|
||||||
|
self.setFormat(1, len(theText), self.hStyles["header1h"])
|
||||||
|
|
||||||
else:
|
elif theText.startswith("## "): # Header 2
|
||||||
# For other text, just use our regex rules
|
self.setFormat(0, 2, self.hStyles["header2"])
|
||||||
|
self.setFormat(2, len(theText), self.hStyles["header2h"])
|
||||||
|
|
||||||
|
elif theText.startswith("### "): # Header 3
|
||||||
|
self.setFormat(0, 3, self.hStyles["header3"])
|
||||||
|
self.setFormat(3, len(theText), self.hStyles["header3h"])
|
||||||
|
|
||||||
|
elif theText.startswith("#### "): # Header 4
|
||||||
|
self.setFormat(0, 4, self.hStyles["header4"])
|
||||||
|
self.setFormat(4, len(theText), self.hStyles["header4h"])
|
||||||
|
|
||||||
|
elif theText.startswith("%"): # Comments
|
||||||
|
self.setFormat(0, len(theText), self.hStyles["hidden"])
|
||||||
|
|
||||||
|
else: # Text Paragraph
|
||||||
for rX, xFmt in self.rxRules:
|
for rX, xFmt in self.rxRules:
|
||||||
rxItt = rX.globalMatch(theText, 0)
|
rxItt = rX.globalMatch(theText, 0)
|
||||||
while rxItt.hasNext():
|
while rxItt.hasNext():
|
||||||
|
|||||||
Reference in New Issue
Block a user