From 7b6a67e520c04f56b4b05fa26b252177398df6df Mon Sep 17 00:00:00 2001 From: Eugene Popov Date: Tue, 25 Apr 2023 13:05:39 +0000 Subject: Fix activating the Selection Mode with a keyboard shortcut If a spacebar is used as a keyboard shortcut to activate the Selection Mode, then allow this shortcut to be triggered only if the view has a keyboard focus. BUG: 465489 --- src/kitemviews/kitemlistcontroller.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/kitemviews/kitemlistcontroller.cpp') diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp index 0c9f19f55..2e7d2f057 100644 --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -228,6 +228,11 @@ bool KItemListController::selectionMode() const return m_selectionMode; } +bool KItemListController::isSearchAsYouTypeActive() const +{ + return m_keyboardManager->isSearchAsYouTypeActive(); +} + bool KItemListController::keyPressEvent(QKeyEvent *event) { int index = m_selectionManager->currentItem(); @@ -439,10 +444,13 @@ bool KItemListController::keyPressEvent(QKeyEvent *event) m_selectionManager->setSelected(index, 1, KItemListSelectionManager::Toggle); m_selectionManager->beginAnchoredSelection(index); 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; + } 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; + } } } Q_FALLTHROUGH(); // fall through to the default case and add the Space to the current search string. -- cgit v1.3