]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Make space shortcut for selection mode view-local instead of global
authorFelix Ernst <fe.a.ernst@gmail.com>
Mon, 2 Jan 2023 15:01:49 +0000 (16:01 +0100)
committerFelix Ernst <fe.a.ernst@gmail.com>
Wed, 11 Jan 2023 14:49:20 +0000 (15:49 +0100)
Before this commit, the "Space" keyboard shortcut was bound to
triggering selection mode by default. After this commit, pressing
"Space" will only trigger selection mode when the file view area
has keyboard focus.

Pros:
+ Other buttons in the UI can be triggered with Space once again
  just like it is expected from an accessibility point of view.
+ "Type-ahead" searching works once more when typing the space
  char for file names containing such a space char.

Cons:
- "Space" can no longer be used to add the currently underlined
  item to the selection. Instead "Ctrl+Space" needs to be used.
  (However, this is the current status anyway unless a user has
  manually unbound "Space" as a shortcut from Selection Mode.)
- The Selection Mode action will no longer show "Space" as its
  shortcut in menus.

Overall, I see solutions to all of these problems, but they seem
over-engineered for the issues they are trying to solve, so I
believe this somewhat small commit is the best solution for now.

BUG: 458282
BUG: 458281
CCBUG: 463048
FIXED-IN: 23.04

src/dolphinmainwindow.cpp
src/kitemviews/kitemlistcontroller.cpp
src/kitemviews/private/kitemlistkeyboardsearchmanager.cpp
src/kitemviews/private/kitemlistkeyboardsearchmanager.h

index f3ec70753ca4f502b10fda1a3ea2915602cbd460..9a73ecd26ce8ba357a7161aae62767d2caa6e2b5 100644 (file)
@@ -1705,7 +1705,6 @@ void DolphinMainWindow::setupActions()
         "</para>"));
     toggleSelectionModeAction->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
     toggleSelectionModeAction->setCheckable(true);
-    actionCollection()->setDefaultShortcut(toggleSelectionModeAction, Qt::Key_Space );
     connect(toggleSelectionModeAction, &QAction::triggered, this, &DolphinMainWindow::toggleSelectionMode);
 
     // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
index 955e418e8ea893f5b4a3dd163140e26f27b29ef5..29a5bd87ad8a96ecff209e9a5a85b89943bc304b 100644 (file)
@@ -436,13 +436,10 @@ bool KItemListController::keyPressEvent(QKeyEvent* event)
                 m_selectionManager->setSelected(index, 1, KItemListSelectionManager::Toggle);
                 m_selectionManager->beginAnchoredSelection(index);
                 break;
-            } else {
-                // Select the current item if it is not selected yet.
-                const int current = m_selectionManager->currentItem();
-                if (!m_selectionManager->isSelected(current)) {
-                    m_selectionManager->setSelected(current);
-                    break;
-                }
+            } else if (m_keyboardManager->addKeyBeginsNewSearch()) { // File names shouldn't start with a space,
+                                                                     // so we can use this press as a keyboard shortcut instead.
+                Q_EMIT selectionModeChangeRequested(!m_selectionMode);
+                break;
             }
         }
         Q_FALLTHROUGH();  // fall through to the default case and add the Space to the current search string.
index 0e6280edeffe8930f2238f071fd5763a0fb30f76..e646a6249d534131ca24618dd151202ada3088ee 100644 (file)
@@ -63,6 +63,11 @@ void KItemListKeyboardSearchManager::addKeys(const QString& keys)
     m_keyboardInputTime.start();
 }
 
+bool KItemListKeyboardSearchManager::addKeyBeginsNewSearch() const
+{
+    return m_keyboardInputTime.hasExpired(m_timeout) || m_searchedString.isEmpty();
+}
+
 void KItemListKeyboardSearchManager::setTimeout(qint64 milliseconds)
 {
     m_timeout = milliseconds;
index 72f5695ce54e2554dac7d80a4c91a7a3aec66538..80caea2ed25c55f73a3bf7b5c9ec17cf9a0d380e 100644 (file)
@@ -35,6 +35,11 @@ public:
      * Add \a keys to the text buffer used for searching.
      */
     void addKeys(const QString& keys);
+    /**
+     * @returns true if the next call to addKeys() will trigger a new search.
+     *          Returns false if the next added key char will be added to the search string that was used previously.
+     */
+    bool addKeyBeginsNewSearch() const;
 
     /**
      * Sets the delay after which the search is cancelled to \a milliseconds.
@@ -46,7 +51,6 @@ public:
     qint64 timeout() const;
 
     void cancelSearch();
-    bool shouldClearSearchIfInputTimeReached();
 
 public Q_SLOTS:
 
@@ -65,10 +69,15 @@ Q_SIGNALS:
     // (see https://doc.qt.io/archives/qq/qq13-apis.html#thebooleanparametertrap)
     void changeCurrentItem(const QString& string, bool searchFromNextItem);
 
+private:
+    bool shouldClearSearchIfInputTimeReached();
+
 private:
     QString m_searchedString;
     bool m_isSearchRestarted;
+    /** Measures the time since the last key press. */
     QElapsedTimer m_keyboardInputTime;
+    /** Time in milliseconds in which a key press is considered as a continuation of the previous search input. */
     qint64 m_timeout;
 };