File: upstream_719e0b00_KFileWidget-Fix-key-navigation-escaping-in-save-dialogs.patch

package info (click to toggle)
kf6-kio 6.13.0-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 38,544 kB
  • sloc: cpp: 101,030; xml: 578; ansic: 215; python: 186; ruby: 60; sh: 21; makefile: 17
file content (143 lines) | stat: -rw-r--r-- 5,037 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
From 719e0b0031155ef83a2cf71d6d24114dea181353 Mon Sep 17 00:00:00 2001
From: Akseli Lahtinen <akselmo@akselmo.dev>
Date: Wed, 7 May 2025 16:35:19 +0300
Subject: [PATCH] KFileWidget: Fix key navigation escaping in save dialogs

In save dialogs the keyboard navigation would escape during file
highlighting, since the fileHighlight sets the focus for fileName bar
for mouse operations.

This makes sure the user has to press Tab to explicitly escape the
keyboard navigation mode. For clicking the items, it should not affect
at all.

CCBUG: 466206
FIXED-IN: 6.14
(cherry picked from commit 8e4e84f045b7459c0b02b1b1b51a9df73cea068a)
---
 src/filewidgets/kdiroperator.cpp | 21 +++++++++++++++++++++
 src/filewidgets/kdiroperator.h   |  7 +++++++
 src/filewidgets/kfilewidget.cpp  |  8 ++++----
 3 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/src/filewidgets/kdiroperator.cpp b/src/filewidgets/kdiroperator.cpp
index e1d3afeea..4a2e400c7 100644
--- a/src/filewidgets/kdiroperator.cpp
+++ b/src/filewidgets/kdiroperator.cpp
@@ -221,6 +221,7 @@ public:
     bool m_showOpenWithActions = false;
     bool m_isTouchEvent = false;
     bool m_isTouchDrag = false;
+    bool m_keyNavigation = false;
 
     QList<QUrl> m_itemsToBeSetAsCurrent;
     QStringList m_supportedSchemes;
@@ -1244,6 +1245,11 @@ void KDirOperator::showOpenWithActions(bool enable)
     d->m_showOpenWithActions = enable;
 }
 
+bool KDirOperator::usingKeyNavigation()
+{
+    return d->m_keyNavigation;
+}
+
 void KDirOperator::changeEvent(QEvent *event)
 {
     QWidget::changeEvent(event);
@@ -1429,6 +1435,19 @@ bool KDirOperator::eventFilter(QObject *watched, QEvent *event)
                 return true;
             }
         }
+        // Only use tab key to escape the view navigation
+        if (evt->key() == Qt::Key_Tab) {
+            d->m_keyNavigation = false;
+            d->slotSelectionChanged();
+            // When saving we need to return here,
+            // otherwise we skip over the next item with our tab press
+            // since we focus on that item in slotSelectionChanged
+            if (d->m_isSaving) {
+                return true;
+            }
+        } else {
+            d->m_keyNavigation = true;
+        }
         break;
     }
     case QEvent::Resize: {
@@ -1833,6 +1852,7 @@ void KDirOperator::selectFile(const KFileItem &item)
     QApplication::restoreOverrideCursor();
 
     Q_EMIT fileSelected(item);
+    d->m_keyNavigation = false;
 }
 
 void KDirOperator::highlightFile(const KFileItem &item)
@@ -1842,6 +1862,7 @@ void KDirOperator::highlightFile(const KFileItem &item)
     }
 
     Q_EMIT fileHighlighted(item);
+    d->m_keyNavigation = false;
 }
 
 void KDirOperator::setCurrentItem(const QUrl &url)
diff --git a/src/filewidgets/kdiroperator.h b/src/filewidgets/kdiroperator.h
index c34880564..71a20ed2e 100644
--- a/src/filewidgets/kdiroperator.h
+++ b/src/filewidgets/kdiroperator.h
@@ -744,6 +744,13 @@ public:
      */
     void showOpenWithActions(bool enable);
 
+    /*!
+     * @returns true if the user was using keys to navigate.
+     *
+     * \since 6.14
+     */
+    bool usingKeyNavigation();
+
 protected:
     /**
      * A view factory for creating predefined fileviews. Called internally by setView,
diff --git a/src/filewidgets/kfilewidget.cpp b/src/filewidgets/kfilewidget.cpp
index 5175a085a..017e65d1e 100644
--- a/src/filewidgets/kfilewidget.cpp
+++ b/src/filewidgets/kfilewidget.cpp
@@ -168,7 +168,7 @@ public:
     void enterUrl(const QString &);
     void locationAccepted(const QString &);
     void slotFilterChanged();
-    void fileHighlighted(const KFileItem &);
+    void fileHighlighted(const KFileItem &, bool);
     void fileSelected(const KFileItem &);
     void slotLoadingFinished();
     void togglePlacesPanel(bool show, QObject *sender = nullptr);
@@ -894,7 +894,7 @@ void KFileWidget::accept()
     d->m_ops->close();
 }
 
-void KFileWidgetPrivate::fileHighlighted(const KFileItem &i)
+void KFileWidgetPrivate::fileHighlighted(const KFileItem &i, bool isKeyNavigation)
 {
     if ((m_locationEdit->hasFocus() && !m_locationEdit->currentText().isEmpty())) { // don't disturb
         return;
@@ -933,7 +933,7 @@ void KFileWidgetPrivate::fileHighlighted(const KFileItem &i)
     // rename it if desired
     // Note that double-clicking will override this and overwrite regardless of
     // single/double click mouse setting (see slotViewDoubleClicked() )
-    if (m_operationMode == KFileWidget::Saving) {
+    if (!isKeyNavigation && m_operationMode == KFileWidget::Saving) {
         m_locationEdit->setFocus();
     }
 }
@@ -1100,7 +1100,7 @@ void KFileWidgetPrivate::initDirOpWidgets()
         urlEntered(url);
     });
     q->connect(m_ops, &KDirOperator::fileHighlighted, q, [this](const KFileItem &item) {
-        fileHighlighted(item);
+        fileHighlighted(item, m_ops->usingKeyNavigation());
     });
     q->connect(m_ops, &KDirOperator::fileSelected, q, [this](const KFileItem &item) {
         fileSelected(item);
-- 
GitLab