From 73cd7f7513e7eb9ed9baf08ca77f11cea881af2d Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sat, 9 Jan 2021 20:26:05 +0100 Subject: [PATCH] Improve doc changed checking and some code cleanup --- nw/gui/doceditor.py | 11 ++++++++--- nw/gui/statusbar.py | 9 ++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index c2978b00..3421276c 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -903,12 +903,13 @@ class GuiDocEditor(QTextEdit): ## @pyqtSlot(int, int, int) - def _docChange(self, thePos, charsRemoved, charsAdded): + def _docChange(self, thePos, chrRem, chrAdd): """Triggered by QTextDocument->contentsChanged. This also triggers the syntax highlighter. """ self.lastEdit = time() self.lastFind = None + if self.qDocument.characterCount() > nwConst.MAX_DOCSIZE: self.theParent.makeAlert(( "The document has grown too big and you cannot add more text to it. " @@ -916,12 +917,16 @@ class GuiDocEditor(QTextEdit): ) % (nwConst.MAX_DOCSIZE/1.0e6), nwAlert.ERROR) self.undo() return + if not self.docChanged: - self.setDocumentChanged(True) + self.setDocumentChanged(chrRem != 0 or chrAdd != 0) + if not self.wcTimer.isActive(): self.wcTimer.start() - if self.doReplace and charsAdded == 1: + + if self.doReplace and chrAdd == 1: self._docAutoReplace(self.qDocument.findBlock(thePos)) + return @pyqtSlot("QPoint") diff --git a/nw/gui/statusbar.py b/nw/gui/statusbar.py index bbebb7cb..e1738447 100644 --- a/nw/gui/statusbar.py +++ b/nw/gui/statusbar.py @@ -179,13 +179,8 @@ class GuiMainStatus(QStatusBar): def setStats(self, pWC, sWC): """Set the current project statistics. """ - self.statsText.setToolTip( - "Project word count (session change)" - ) - self.statsText.setText( - f"Words: {pWC:n} ({sWC:+n})" - ) - + self.statsText.setText(f"Words: {pWC:n} ({sWC:+n})") + self.statsText.setToolTip("Project word count (session change)") return ##