From fb2644e5bec67ac7efb3a2c9f959dc73cfa9f721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Candice=20Bent=C3=A9jac?= Date: Fri, 23 Aug 2024 18:16:25 +0200 Subject: [PATCH] [Controls] FilterComboBox: Correctly cancel selection or edition Up until this commit, any action causing the filtering text field to lose the focus was considered to be a valid edition, thus propagating the value in the text field or the one highlighted to be propagated, even if the user was clicking anywhere else in the application, or pressing the `esc` key. The distinction is now made between cases where the edition is finished because it was validated (value clicked on, or selected with the `return`/ `enter` key), and not because it was cancelled (clicks outside of the combobox or `esc` key pressed). --- meshroom/ui/qml/Controls/FilterComboBox.qml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/meshroom/ui/qml/Controls/FilterComboBox.qml b/meshroom/ui/qml/Controls/FilterComboBox.qml index 2463b35489..c9d3a1cd7a 100644 --- a/meshroom/ui/qml/Controls/FilterComboBox.qml +++ b/meshroom/ui/qml/Controls/FilterComboBox.qml @@ -18,6 +18,7 @@ ComboBox { property alias filterText: filterTextArea property bool validValue: true + property string previousText: "" // Used to restore displayText if the edition is cancelled enabled: root.editable model: { @@ -73,6 +74,9 @@ ComboBox { onAboutToShow: { filterTextArea.forceActiveFocus() + filterTextArea.editingCancelled = true + + previousText = displayText var dropDown = true var posY = mapToGlobal(popup.x, popup.y).y @@ -101,6 +105,8 @@ ComboBox { anchors.fill: parent TextArea { id: filterTextArea + + property bool editingCancelled: false leftPadding: 12 anchors.left: parent.left anchors.right: parent.right @@ -114,7 +120,11 @@ ComboBox { onEditingFinished: { combo.popup.close() - combo.editingFinished(displayText) + if (editingCancelled) { + displayText = previousText + } else { + combo.editingFinished(displayText) + } } Keys.onEnterPressed: { @@ -123,6 +133,7 @@ ComboBox { } else { displayText = currentText } + editingCancelled = false editingFinished() } @@ -132,6 +143,7 @@ ComboBox { } else { displayText = currentText } + editingCancelled = false editingFinished() } @@ -200,4 +212,9 @@ ComboBox { onCurrentTextChanged: { displayText = currentText } + + onActivated: { + // This slot is entered when one of the element of the combo is clicked on, causing the popup to close + filterTextArea.editingCancelled = false + } }