Skip to content

Commit

Permalink
[Controls] FilterComboBox: Correctly cancel selection or edition
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
cbentejac committed Aug 23, 2024
1 parent 008ebdb commit fb2644e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion meshroom/ui/qml/Controls/FilterComboBox.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -73,6 +74,9 @@ ComboBox {

onAboutToShow: {
filterTextArea.forceActiveFocus()
filterTextArea.editingCancelled = true

previousText = displayText

var dropDown = true
var posY = mapToGlobal(popup.x, popup.y).y
Expand Down Expand Up @@ -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
Expand All @@ -114,7 +120,11 @@ ComboBox {

onEditingFinished: {
combo.popup.close()
combo.editingFinished(displayText)
if (editingCancelled) {
displayText = previousText
} else {
combo.editingFinished(displayText)
}
}

Keys.onEnterPressed: {
Expand All @@ -123,6 +133,7 @@ ComboBox {
} else {
displayText = currentText
}
editingCancelled = false
editingFinished()
}

Expand All @@ -132,6 +143,7 @@ ComboBox {
} else {
displayText = currentText
}
editingCancelled = false
editingFinished()
}

Expand Down Expand Up @@ -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
}
}

0 comments on commit fb2644e

Please sign in to comment.