[education/rkward] rkward/windows: Try to keep scroll position when reloading PDF

Thomas Friedrichsmeier null at kde.org
Tue Jul 9 12:55:52 BST 2024


Git commit 1188313de9265436e45b77d9d24253539f040198 by Thomas Friedrichsmeier.
Committed on 09/07/2024 at 11:55.
Pushed by tfry into branch 'master'.

Try to keep scroll position when reloading PDF

M  +15   -1    rkward/windows/rkpdfwindow.cpp

https://invent.kde.org/education/rkward/-/commit/1188313de9265436e45b77d9d24253539f040198

diff --git a/rkward/windows/rkpdfwindow.cpp b/rkward/windows/rkpdfwindow.cpp
index 51450bbd5..12d3e3326 100644
--- a/rkward/windows/rkpdfwindow.cpp
+++ b/rkward/windows/rkpdfwindow.cpp
@@ -43,7 +43,21 @@ RKPDFWindow::~RKPDFWindow() {
 
 void RKPDFWindow::openURL(const QUrl &url) {
 	RK_TRACE(APP);
-	if (valid) static_cast<KParts::ReadOnlyPart*>(getPart())->openUrl(url);
+	if (valid) {
+		auto p = static_cast<KParts::ReadOnlyPart*>(getPart());
+		if (url == p->url()) {
+			// If reloading existing file, use reload mechanism, in order to keep scroll position
+			// NOTE: Okular part appears to auto-reload local files, anyway, but I'd like not to rely on thie behavior
+			// NOTE: I tried KParts::NavigationExtension / KParts::OpenUrlArguments for a reload saving scroll position, but somehow
+			//       that did not work, reliably (possibly a race condition with the auto-reload, above).
+			auto reload = p->action("file_reload");
+			if (reload) {
+				reload->trigger();
+				return;
+			}
+		}
+		p->openUrl(url);  // no "reload" action found or navigating to differen url
+	}
 	setWindowTitle(url.fileName());
 	Q_EMIT captionChanged(this);
 }


More information about the rkward-tracker mailing list