[education/rkward] rkward/windows: Do not open help pages twice

Thomas Friedrichsmeier null at kde.org
Thu Apr 9 20:44:24 BST 2026


Git commit 01f395770ff78011fb2415c39983d95bfdb4613c by Thomas Friedrichsmeier.
Committed on 09/04/2026 at 19:44.
Pushed by tfry into branch 'master'.

Do not open help pages twice

M  +5    -3    rkward/windows/rkqwebview.cpp
M  +6    -0    rkward/windows/rkqwebview.qml

https://invent.kde.org/education/rkward/-/commit/01f395770ff78011fb2415c39983d95bfdb4613c

diff --git a/rkward/windows/rkqwebview.cpp b/rkward/windows/rkqwebview.cpp
index e6d7eeaa1..208196fc1 100644
--- a/rkward/windows/rkqwebview.cpp
+++ b/rkward/windows/rkqwebview.cpp
@@ -26,14 +26,16 @@ QUrl RKQWebView::currentAcceptedUrl() const {
 }
 
 void RKQWebView::onUrlChanged(const QUrl &_url, const QString &error, int status) {
-	RK_DEBUG(APP, DL_DEBUG, "webview url changed to %s status %d, msg %s", qPrintable(_url.toString()), status, qPrintable(error));
+	// WebView status enum: 0: LoadStarted, 2: LoadFinished, 3: Error.
+	// I do not actually know, what status==1 is, but it does get sent in some cases. I assume it's "aborted"
+	RK_DEBUG(APP, DL_WARNING, "webview %p url changed to %s status %d, msg %s", this, qPrintable(_url.toString()), status, qPrintable(error));
 	bool new_window = false;
 	Q_EMIT navigationRequest(currentAcceptedUrl(), _url, new_window);
 	// we may be redirected via the above signal
 	if (_url != url()) {
 		RK_DEBUG(APP, DL_DEBUG, "redirecting %s to %s", qPrintable(_url.toString()), qPrintable(url().toString()));
 	}
-	if (status == 0 && _url.scheme() == u"rkward") {
+	if (status == 0 && _url.scheme() == u"rkward"_s) {
 		// Some QWebView plugins will also trigger openRKWardURl() via QDesktopServices::setUrlHandler()
 		// Others won't. In either case, we've handled it from here.
 		RKWorkplace::mainWorkplace()->suppressRKWardUrlHandling(_url);
@@ -57,7 +59,7 @@ QWidget *RKQWebView::createWidget() {
 	connect(webView(), SIGNAL(pageUrlChanged(const QUrl &, const QString &, int)), this, SLOT(onUrlChanged(const QUrl &, const QString &, int)));
 	connect(webView(), SIGNAL(loadFinished(const QUrl &)), this, SLOT(onLoadFinished(const QUrl &)));
 	connect(webView(), SIGNAL(runJSResult(const QVariant &)), this, SLOT(onRunJSResult(const QVariant &)));
-	/* TODO: we may need to inject a script similar for handling target=new
+	/* TODO: we may need to inject a script along the lines below for handling target=new
 	    and page internal navigation?
 	RKHTMLViewer::runJS(u"document.addEventListener('click', e => {"
 	    "  const origin = e.target.closest('a');"
diff --git a/rkward/windows/rkqwebview.qml b/rkward/windows/rkqwebview.qml
index 1efc367a2..ca84b899d 100644
--- a/rkward/windows/rkqwebview.qml
+++ b/rkward/windows/rkqwebview.qml
@@ -26,6 +26,7 @@ Item {
                 width: parent.width
                 height: parent.height
                 property string acceptedUrl: ""
+                property string requestedUrl: ""
 
                 onLoadingChanged: request => {
                         // notify frontend of any url changes, giving it a chance to intervene (e.g. rewriting
@@ -35,6 +36,11 @@ Item {
                         // while for webview2, we only get LoadFailedStatus.
                         if (request.url != acceptedUrl) {
                                 pageUrlChanged(request.url, request.error, request.status);
+                                // if request did not get accepted: stay
+                                if (requestedUrl != acceptedUrl) {
+                                        // TODO: save and restore scroll position
+                                        url = acceptedUrl;
+                                }
                         }
                         if (request.status == WebView.LoadSucceededStatus) {
                                 loadFinished(request.url);



More information about the rkward-tracker mailing list