From 39612ade13b20b926d0cd0311ca4afbd0f8882fa Mon Sep 17 00:00:00 2001 From: Niklas Stephanblome Date: Fri, 30 Dec 2022 17:44:48 +0000 Subject: [PATCH] effects/overview: allow entering spaces in search field In the Overview effect, pressing the space bar doesn't always insert a space character into the search field as one would expect; when the text in the search field matches any windows, it instead activates the highlighted window. At other times, it does insert a space as expected. This behavior is unpredictable and unintuitive, so this commit fixes the issue by intercepting the key input event and inserting a space when the search field has focus. In this state, the highlighted window can be activated using the enter/return key. When the search field doesn't have focus, a press of the space bar will continue to activate the selected window. --- src/effects/overview/qml/ScreenView.qml | 2 +- src/effects/private/qml/WindowHeap.qml | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/effects/overview/qml/ScreenView.qml b/src/effects/overview/qml/ScreenView.qml index 71b55a768e..9d7e86a5d1 100644 --- a/src/effects/overview/qml/ScreenView.qml +++ b/src/effects/overview/qml/ScreenView.qml @@ -40,7 +40,6 @@ FocusScope { Keys.onEscapePressed: effect.deactivate(); - Keys.priority: Keys.AfterItem Keys.forwardTo: searchField Keys.onEnterPressed: { @@ -209,6 +208,7 @@ FocusScope { effect.searchText = text; heap.resetSelected(); heap.selectNextItem(WindowHeap.Direction.Down); + searchField.focus = true; } } } diff --git a/src/effects/private/qml/WindowHeap.qml b/src/effects/private/qml/WindowHeap.qml index 3bc55f870e..98a8508623 100644 --- a/src/effects/private/qml/WindowHeap.qml +++ b/src/effects/private/qml/WindowHeap.qml @@ -309,37 +309,47 @@ FocusScope { return false; } - onActiveFocusChanged: resetSelected(); Keys.onPressed: { let handled = false; switch (event.key) { case Qt.Key_Up: handled = selectNextItem(WindowHeap.Direction.Up); + heap.focus = true; break; case Qt.Key_Down: handled = selectNextItem(WindowHeap.Direction.Down); + heap.focus = true; break; case Qt.Key_Left: handled = selectNextItem(WindowHeap.Direction.Left); + heap.focus = true; break; case Qt.Key_Right: handled = selectNextItem(WindowHeap.Direction.Right); + heap.focus = true; break; case Qt.Key_Home: handled = selectLastItem(WindowHeap.Direction.Left); + heap.focus = true; break; case Qt.Key_End: handled = selectLastItem(WindowHeap.Direction.Right); + heap.focus = true; break; case Qt.Key_PageUp: handled = selectLastItem(WindowHeap.Direction.Up); + heap.focus = true; break; case Qt.Key_PageDown: handled = selectLastItem(WindowHeap.Direction.Down); + heap.focus = true; break; - case Qt.Key_Return: case Qt.Key_Space: + if (!heap.focus) { + break; + } + case Qt.Key_Return: handled = false; let selectedItem = null; if (selectedIndex !== -1) {