From 702868a099c5ea27cf1759dd8e36d912561d08ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Candice=20Bent=C3=A9jac?= Date: Mon, 26 Aug 2024 08:40:18 +0100 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 | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/meshroom/ui/qml/Controls/FilterComboBox.qml b/meshroom/ui/qml/Controls/FilterComboBox.qml index 2463b35489..4e672c8476 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,12 @@ ComboBox { onEditingFinished: { combo.popup.close() - combo.editingFinished(displayText) + if (editingCancelled) { + displayText = previousText + filterTextArea.clear() + } else { + combo.editingFinished(displayText) + } } Keys.onEnterPressed: { @@ -123,6 +134,7 @@ ComboBox { } else { displayText = currentText } + editingCancelled = false editingFinished() } @@ -132,6 +144,7 @@ ComboBox { } else { displayText = currentText } + editingCancelled = false editingFinished() } @@ -200,4 +213,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 + } }