From e19ed0b44b9a28bb73b9e4af55c8c9d647c35acf Mon Sep 17 00:00:00 2001 From: nZo-sp <43019+nZo-sp@users.noreply.github.com> Date: Thu, 19 Mar 2026 17:19:29 +0100 Subject: [PATCH 1/2] Added scroll with keyboard on dropdown --- Widgets/NSearchableComboBox.qml | 94 ++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/Widgets/NSearchableComboBox.qml b/Widgets/NSearchableComboBox.qml index 6ad6fd1f4..c0e00edc9 100644 --- a/Widgets/NSearchableComboBox.qml +++ b/Widgets/NSearchableComboBox.qml @@ -10,6 +10,7 @@ RowLayout { property real minimumWidth: 280 property real popupHeight: 180 + property bool selectOnNavigation: true property string label: "" property string description: "" property ListModel model: {} @@ -152,7 +153,10 @@ RowLayout { } } - onSearchTextChanged: filterModel() + onSearchTextChanged: { + filterModel(); + listView.currentIndex = 0; + } NLabel { label: root.label @@ -236,6 +240,86 @@ RowLayout { text: root.searchText onTextChanged: root.searchText = text fontSize: Style.fontSizeS + + Keys.onUpPressed: { + if (listView.currentIndex > 0) { + listView.currentIndex--; + listView.positionViewAtIndex(listView.currentIndex, ListView.Contain); + + if (root.selectOnNavigation) { + selectHighlighted() + } + } + } + + Keys.onDownPressed: { + if (listView.currentIndex < listView.count - 1) { + listView.currentIndex++; + listView.positionViewAtIndex(listView.currentIndex, ListView.Contain); + + if (root.selectOnNavigation) { + selectHighlighted() + } + } + } + + Keys.onReturnPressed: { + selectHighlighted() + combo.popup.close(); + } + Keys.onEnterPressed: { + selectHighlighted() + combo.popup.close(); + } + + Keys.onEscapePressed: combo.popup.close() + + Keys.onPressed: (event) => { + switch (event.key) { + case Qt.Key_Home: + listView.currentIndex = 0; + listView.positionViewAtIndex(0, ListView.Beginning); + event.accepted = true; + break; + case Qt.Key_End: + listView.currentIndex = listView.count - 1; + listView.positionViewAtIndex(listView.count - 1, ListView.End); + event.accepted = true; + break; + case Qt.Key_PageUp: + listView.currentIndex = Math.max(0, listView.currentIndex - pageStep()); + listView.positionViewAtIndex(listView.currentIndex, ListView.Contain); + event.accepted = true; + break; + case Qt.Key_PageDown: + listView.currentIndex = Math.min(listView.count - 1, listView.currentIndex + pageStep()); + listView.positionViewAtIndex(listView.currentIndex, ListView.Contain); + event.accepted = true; + break; + default: + return; + } + + if (root.selectOnNavigation) { + selectHighlighted() + } + } + + function selectHighlighted() { + if (listView.currentIndex >= 0 + && listView.model + && listView.currentIndex < listView.model.count) { + var selectedKey = listView.model.get(listView.currentIndex).key; + root.selected(selectedKey); + } + } + + function pageStep() { + if (listView.count === 0 || listView.contentHeight === 0) + return 1; + var rowHeight = listView.contentHeight / listView.count; + return Math.max(1, Math.floor(listView.height / rowHeight)); + } } NListView { @@ -247,6 +331,11 @@ RowLayout { horizontalPolicy: ScrollBar.AlwaysOff verticalPolicy: ScrollBar.AsNeeded + onCurrentIndexChanged: { + if (currentIndex >= 0) + positionViewAtIndex(currentIndex, ListView.Contain); + } + delegate: root.delegate ? root.delegate : defaultDelegate Component { @@ -378,12 +467,15 @@ RowLayout { if (combo.popup.visible) { // Ensure the model is filtered when popup opens filterModel(); + listView.currentIndex = Math.max(0, root.findIndexInActiveModel(root.currentKey)); // Small delay to ensure the popup is fully rendered Qt.callLater(() => { if (searchInput && searchInput.inputItem) { searchInput.inputItem.forceActiveFocus(); } }); + } else { + root.searchText = ""; } } } From e6716a745f10c0f8e9809a6bba25221a7aefcb24 Mon Sep 17 00:00:00 2001 From: nZo-sp <43019+nZo-sp@users.noreply.github.com> Date: Mon, 23 Mar 2026 09:00:49 +0100 Subject: [PATCH 2/2] Using keybind from settings --- Widgets/NSearchableComboBox.qml | 89 ++++++++++++--------------------- 1 file changed, 31 insertions(+), 58 deletions(-) diff --git a/Widgets/NSearchableComboBox.qml b/Widgets/NSearchableComboBox.qml index c0e00edc9..5baa0479f 100644 --- a/Widgets/NSearchableComboBox.qml +++ b/Widgets/NSearchableComboBox.qml @@ -241,67 +241,40 @@ RowLayout { onTextChanged: root.searchText = text fontSize: Style.fontSizeS - Keys.onUpPressed: { - if (listView.currentIndex > 0) { - listView.currentIndex--; - listView.positionViewAtIndex(listView.currentIndex, ListView.Contain); - - if (root.selectOnNavigation) { - selectHighlighted() - } - } - } - - Keys.onDownPressed: { - if (listView.currentIndex < listView.count - 1) { - listView.currentIndex++; - listView.positionViewAtIndex(listView.currentIndex, ListView.Contain); - - if (root.selectOnNavigation) { - selectHighlighted() - } - } - } - - Keys.onReturnPressed: { - selectHighlighted() - combo.popup.close(); - } - Keys.onEnterPressed: { - selectHighlighted() - combo.popup.close(); - } - - Keys.onEscapePressed: combo.popup.close() - Keys.onPressed: (event) => { - switch (event.key) { - case Qt.Key_Home: - listView.currentIndex = 0; - listView.positionViewAtIndex(0, ListView.Beginning); - event.accepted = true; - break; - case Qt.Key_End: - listView.currentIndex = listView.count - 1; - listView.positionViewAtIndex(listView.count - 1, ListView.End); - event.accepted = true; - break; - case Qt.Key_PageUp: - listView.currentIndex = Math.max(0, listView.currentIndex - pageStep()); - listView.positionViewAtIndex(listView.currentIndex, ListView.Contain); - event.accepted = true; - break; - case Qt.Key_PageDown: - listView.currentIndex = Math.min(listView.count - 1, listView.currentIndex + pageStep()); - listView.positionViewAtIndex(listView.currentIndex, ListView.Contain); - event.accepted = true; - break; - default: - return; + if (Keybinds.checkKey(event, 'enter', Settings)) { + selectHighlighted() + combo.popup.close(); + event.accepted = true; + return; } - if (root.selectOnNavigation) { - selectHighlighted() + if (Keybinds.checkKey(event, 'escape', Settings)) { + combo.popup.close() + event.accepted = true; + return; + } + + if (Keybinds.checkKey(event, 'up', Settings)) { + if (listView.currentIndex > 0) { + listView.currentIndex--; + listView.positionViewAtIndex(listView.currentIndex, ListView.Contain); + if (root.selectOnNavigation) + selectHighlighted(); + } + event.accepted = true; + return; + } + + if (Keybinds.checkKey(event, 'down', Settings)) { + if (listView.currentIndex < listView.count - 1) { + listView.currentIndex++; + listView.positionViewAtIndex(listView.currentIndex, ListView.Contain); + if (root.selectOnNavigation) + selectHighlighted(); + } + event.accepted = true; + return; } }