From 7b26e38f33e2e0064263682a14b8487ba327b51a Mon Sep 17 00:00:00 2001 From: LemmyCook Date: Thu, 4 Sep 2025 17:03:11 -0400 Subject: [PATCH] Launcher: improved/fixed keyboard controls (Ctrl+J / Ctrl+K) --- Modules/Launcher/Launcher.qml | 97 +++++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 34 deletions(-) diff --git a/Modules/Launcher/Launcher.qml b/Modules/Launcher/Launcher.qml index c417168..a30742e 100644 --- a/Modules/Launcher/Launcher.qml +++ b/Modules/Launcher/Launcher.qml @@ -170,6 +170,7 @@ NPanel { function selectFirst() { selectedIndex = 0 + console.log("selectFirst") } function selectLast() { @@ -202,6 +203,42 @@ NPanel { } } + Shortcut { + sequence: "Ctrl+K" + onActivated: ui.selectPrevious() + enabled: root.opened && searchInput.inputItem && searchInput.inputItem.activeFocus + } + + Shortcut { + sequence: "Ctrl+J" + onActivated: ui.selectNext() + enabled: root.opened && searchInput.inputItem && searchInput.inputItem.activeFocus + } + + Shortcut { + sequence: "PgDown" // or "PageDown" + onActivated: ui.selectNextPage() + enabled: root.opened && searchInput.inputItem && searchInput.inputItem.activeFocus + } + + Shortcut { + sequence: "PgUp" // or "PageUp" + onActivated: ui.selectPreviousPage() + enabled: root.opened && searchInput.inputItem && searchInput.inputItem.activeFocus + } + + Shortcut { + sequence: "Home" + onActivated: ui.selectFirst() + enabled: root.opened && searchInput.inputItem && searchInput.inputItem.activeFocus + } + + Shortcut { + sequence: "End" + onActivated: ui.selectLast() + enabled: root.opened && searchInput.inputItem && searchInput.inputItem.activeFocus + } + ColumnLayout { anchors.fill: parent anchors.margins: Style.marginL * scaling @@ -223,45 +260,37 @@ NPanel { text: searchText placeholderText: "Search entries... or use > for commands" + onTextChanged: searchText = text + Component.onCompleted: { if (searchInput.inputItem && searchInput.inputItem.visible) { searchInput.inputItem.forceActiveFocus() + + // Override the TextField's default Home/End behavior + searchInput.inputItem.Keys.priority = Keys.BeforeItem + searchInput.inputItem.Keys.onPressed.connect(function (event) { + // Intercept Home and End BEFORE the TextField handles them + if (event.key === Qt.Key_Home) { + ui.selectFirst() + event.accepted = true + return + } else if (event.key === Qt.Key_End) { + ui.selectLast() + event.accepted = true + return + } + }) + searchInput.inputItem.Keys.onDownPressed.connect(function (event) { + ui.selectNext() + }) + searchInput.inputItem.Keys.onUpPressed.connect(function (event) { + ui.selectPrevious() + }) + searchInput.inputItem.Keys.onReturnPressed.connect(function (event) { + ui.activate() + }) } } - - onTextChanged: searchText = text - Keys.onEscapePressed: root.close() - Keys.onReturnPressed: ui.activate() - Keys.onDownPressed: ui.selectNext() - Keys.onUpPressed: ui.selectPrevious() - Keys.onPressed: event => { - if (event.key === Qt.Key_PageDown) { - ui.selectNextPage() - event.accepted = true - } else if (event.key === Qt.Key_PageUp) { - ui.selectPreviousPage() - event.accepted = true - } else if (event.key === Qt.Key_Home) { - ui.selectFirst() - event.accepted = true - } else if (event.key === Qt.Key_End) { - ui.selectLast() - event.accepted = true - } - - if (event.modifiers & Qt.ControlModifier) { - switch (event.key) { - case Qt.Key_K: - ui.selectPrevious() - event.accepted = true - break - case Qt.Key_J: - ui.selectNext() - event.accepted = true - break - } - } - } } }