From efdf88be66bcc56bc8e5bc24e089c9485b18de69 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Mon, 5 Oct 2020 20:54:19 +0200 Subject: [PATCH] Drop the doceditor reloadText function as it resets undo stack --- nw/gui/doceditor.py | 26 ++++++++++++++++---------- nw/guimain.py | 4 ++-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index 1410c7b4..14f1db91 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -223,21 +223,12 @@ class GuiDocEditor(QTextEdit): # font changed, otherwise we just clear the editor entirely, # which makes it read only. if self.theHandle is not None: - self.reloadText() + self.redrawText() else: self.clearEditor() return True - def reloadText(self): - """Reloads the document currently being edited. - """ - if self.theHandle is not None: - tHandle = self.theHandle - self.clearEditor() - self.loadText(tHandle, showStatus=False) - return - def loadText(self, tHandle, tLine=None, showStatus=True): """Load text from a document into the editor. If we have an io error, we must handle this and clear the editor so that we don't @@ -297,6 +288,21 @@ class GuiDocEditor(QTextEdit): return True + def reHighLightText(self, forceBigDoc=False): + """Run the syntax highlighter again. + """ + if not self.bigDoc or forceBigDoc: + qApp.setOverrideCursor(QCursor(Qt.WaitCursor)) + self.hLight.rehighlight() + qApp.restoreOverrideCursor() + return + + def redrawText(self): + """Redraw the text by marking the document content as "dirty". + """ + self.qDocument.markContentsDirty(0, self.qDocument.characterCount()) + return + def replaceText(self, theText): """Replaces the text of the current document with the provided text. This also clears undo history. diff --git a/nw/guimain.py b/nw/guimain.py index 5f237bb7..62b2db74 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -716,13 +716,13 @@ class GuiMain(QMainWindow): tEnd = time() self.statusBar.setStatus("Indexing completed in %.1f ms" % ((tEnd - tStart)*1000.0)) - self.docEditor.reloadText() - qApp.restoreOverrideCursor() if not beQuiet: self.makeAlert("The project index has been successfully rebuilt.", nwAlert.INFO) + self.docEditor.reHighLightText() + return True def rebuildOutline(self):