From be7078aa7eb852af2513f8bd73d66b628080348f Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Wed, 29 May 2024 21:26:29 +0200 Subject: [PATCH] Save editor doc before opening same in viewer (#1884) --- novelwriter/gui/docviewer.py | 9 --------- novelwriter/guimain.py | 4 ++++ 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/novelwriter/gui/docviewer.py b/novelwriter/gui/docviewer.py index caee97b9..d73f0abb 100644 --- a/novelwriter/gui/docviewer.py +++ b/novelwriter/gui/docviewer.py @@ -245,9 +245,6 @@ class GuiDocViewer(QTextBrowser): }) self.updateDocMargins() - # Since we change the content while it may still be rendering, we mark - # the document dirty again to make sure it's re-rendered properly. - self.redrawText() QApplication.restoreOverrideCursor() self.documentLoaded.emit(tHandle) @@ -259,12 +256,6 @@ class GuiDocViewer(QTextBrowser): self.loadText(self._docHandle, updateHistory=False) return - def redrawText(self) -> None: - """Redraw the text by marking the content as "dirty".""" - self.document().markContentsDirty(0, self.document().characterCount()) - self.updateDocMargins() - return - def docAction(self, action: nwDocAction) -> bool: """Process document actions on the current document.""" logger.debug("Requesting action: '%s'", action.name) diff --git a/novelwriter/guimain.py b/novelwriter/guimain.py index 0cfe156d..3d6eaf00 100644 --- a/novelwriter/guimain.py +++ b/novelwriter/guimain.py @@ -616,6 +616,10 @@ class GuiMain(QMainWindow): # Make sure main tab is in Editor view self._changeView(nwView.EDITOR) + # If we're loading the document in the editor, it may need to be saved + if tHandle == self.docEditor.docHandle and self.docEditor.docChanged: + self.saveDocument() + logger.debug("Viewing document with handle '%s'", tHandle) updateHistory = tHandle != self.docViewer.docHandle if self.docViewer.loadText(tHandle, updateHistory=updateHistory):