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 26, 2024
1 parent 008ebdb commit 702868a
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 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,12 @@ ComboBox {

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

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

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

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

0 comments on commit 702868a

Please sign in to comment.