diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index 14f1db91..88b6b4bf 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -288,13 +288,10 @@ class GuiDocEditor(QTextEdit): return True - def reHighLightText(self, forceBigDoc=False): - """Run the syntax highlighter again. + def updateTagHighLighting(self, forceBigDoc=False): + """Rerun the syntax highlighter on all meta data lines. """ - if not self.bigDoc or forceBigDoc: - qApp.setOverrideCursor(QCursor(Qt.WaitCursor)) - self.hLight.rehighlight() - qApp.restoreOverrideCursor() + self.hLight.rehighlightByType(GuiDocHighlighter.BLOCK_META) return def redrawText(self): diff --git a/nw/gui/dochighlight.py b/nw/gui/dochighlight.py index 7b95ffeb..663732b4 100644 --- a/nw/gui/dochighlight.py +++ b/nw/gui/dochighlight.py @@ -39,6 +39,11 @@ logger = logging.getLogger(__name__) class GuiDocHighlighter(QSyntaxHighlighter): + BLOCK_NONE = 0 + BLOCK_TEXT = 1 + BLOCK_META = 2 + BLOCK_TITLE = 4 + def __init__(self, theDoc, theParent): QSyntaxHighlighter.__init__(self, theDoc) @@ -229,6 +234,22 @@ class GuiDocHighlighter(QSyntaxHighlighter): self.theHandle = theHandle return True + ## + # Methods + ## + + def rehighlightByType(self, theType): + """Loop through all blocks and rehighlight those of a given + content type. + """ + qDocument = self.document() + nBlocks = qDocument.blockCount() + for i in range(nBlocks): + theBlock = qDocument.findBlockByNumber(i) + if theBlock.userState() & theType == theType: + self.rehighlightBlock(theBlock) + return + ## # Highlight Block ## @@ -239,10 +260,12 @@ class GuiDocHighlighter(QSyntaxHighlighter): is significantly faster than running the regex checks used for text paragraphs. """ + self.setCurrentBlockState(self.BLOCK_NONE) if self.theHandle is None or not theText: return if theText.startswith("@"): # Keywords and commands + self.setCurrentBlockState(self.BLOCK_META) tItem = self.theParent.theProject.projTree[self.theHandle] isValid, theBits, thePos = self.theIndex.scanThis(theText) isGood = self.theIndex.checkThese(theBits, tItem) @@ -266,22 +289,27 @@ class GuiDocHighlighter(QSyntaxHighlighter): return elif theText.startswith("# "): # Header 1 + self.setCurrentBlockState(self.BLOCK_TITLE) self.setFormat(0, 1, self.hStyles["header1h"]) self.setFormat(1, len(theText), self.hStyles["header1"]) elif theText.startswith("## "): # Header 2 + self.setCurrentBlockState(self.BLOCK_TITLE) self.setFormat(0, 2, self.hStyles["header2h"]) self.setFormat(2, len(theText), self.hStyles["header2"]) elif theText.startswith("### "): # Header 3 + self.setCurrentBlockState(self.BLOCK_TITLE) self.setFormat(0, 3, self.hStyles["header3h"]) self.setFormat(3, len(theText), self.hStyles["header3"]) elif theText.startswith("#### "): # Header 4 + self.setCurrentBlockState(self.BLOCK_TITLE) self.setFormat(0, 4, self.hStyles["header4h"]) self.setFormat(4, len(theText), self.hStyles["header4"]) elif theText.startswith("%"): # Comments + self.setCurrentBlockState(self.BLOCK_TEXT) toCheck = theText[1:].lstrip() synTag = toCheck[:9].lower() tLen = len(theText) @@ -294,6 +322,7 @@ class GuiDocHighlighter(QSyntaxHighlighter): self.setFormat(0, tLen, self.hStyles["hidden"]) else: # Text Paragraph + self.setCurrentBlockState(self.BLOCK_TEXT) for rX, xFmt in self.rxRules: rxItt = rX.globalMatch(theText, 0) while rxItt.hasNext(): diff --git a/nw/guimain.py b/nw/guimain.py index 62b2db74..3d60f349 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -716,13 +716,12 @@ class GuiMain(QMainWindow): tEnd = time() self.statusBar.setStatus("Indexing completed in %.1f ms" % ((tEnd - tStart)*1000.0)) + self.docEditor.updateTagHighLighting() qApp.restoreOverrideCursor() if not beQuiet: self.makeAlert("The project index has been successfully rebuilt.", nwAlert.INFO) - self.docEditor.reHighLightText() - return True def rebuildOutline(self):