]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Always focus the view after place activation
authorFelix Ernst <felixernst@zohomail.eu>
Fri, 29 Nov 2024 17:57:37 +0000 (18:57 +0100)
committerFelix Ernst <felixernst@kde.org>
Wed, 4 Dec 2024 13:19:48 +0000 (13:19 +0000)
This one-liner makes sure keyboard focus always moves to the active
view when a place in the places panel is activated. Previously
focus would remain on the places panel if the activated location
was identical to the already displayed location.

This added consistency is helpful because keyboard-only users will
get used to be able to move from the places panel to the view by
pressing the Enter key, even though this does not always work
prior to this commit.

This issue was identified in an accessibility scan done by HAN
University of Applied Science.

src/dolphinmainwindow.cpp
src/tests/dolphinmainwindowtest.cpp

index ead46de30a56ee239442fb69a8e8aa4c5cdb1a9c..e52494c0a49d6c2049e5700392801f8f78f30818 100644 (file)
@@ -1563,6 +1563,8 @@ void DolphinMainWindow::slotPlaceActivated(const QUrl &url)
         // We can end up here if the user clicked a device in the Places Panel
         // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
         reloadView();
+
+        m_activeViewContainer->view()->setFocus(); // We always want the focus on the view after activating a place.
     } else {
         view->disableUrlNavigatorSelectionRequests();
         changeUrl(url);
index cd68bb89339d66f662f2620ccf0b98d18f95ec30..6ac85e4f04a966c54aa4ba99ca71c4f4fdbc190a 100644 (file)
@@ -456,6 +456,18 @@ void DolphinMainWindowTest::testFocusPlacesPanel()
     showPlacesPanelAction->trigger();
     QVERIFY(placesPanel->isVisible());
     QVERIFY2(placesPanel->hasFocus(), "Enabling the Places panel should move keyboard focus there.");
+
+    /// Test that activating a place always moves focus to the view.
+    QTest::keyClick(QApplication::focusWidget(), Qt::Key::Key_Enter);
+    QVERIFY2(m_mainWindow->activeViewContainer()->isAncestorOf(QApplication::focusWidget()),
+             "Activating a place should move focus to the view that loads that place.");
+
+    focusPlacesPanelAction->trigger();
+    QVERIFY(placesPanel->hasFocus());
+
+    QTest::keyClick(QApplication::focusWidget(), Qt::Key::Key_Enter);
+    QVERIFY2(m_mainWindow->activeViewContainer()->isAncestorOf(QApplication::focusWidget()),
+             "Activating a place should move focus to the view even if the view already has that place loaded.");
 }
 
 /**