aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2018-03-12 13:07:12 +0100
committerJ-P Nurmi <jpnurmi@qt.io>2018-03-12 13:03:04 +0000
commit79964673d1587f9e6a254cb6a1f0dd0645b946e6 (patch)
treed10091d0461aea7ec61e353941bfd88a241ca901
parentec9aa9f12142de82315eb6d37f121311ec8408bc (diff)
ComboBox: fix key search in the popup
ComboBox does not change its current index, but highlighted index, when navigating in the popup. If the popup is accepted, the currently highlighted index is applied as the new current index. However, if the popup is rejected, the old current index is kept intact. This is why there is a separation between current and highlighted index. The newly added key search functionality (added together with ComboBox::editable) was missing a check whether the popup is visible. It was unconditionally changing the current index, which lead to a wrong behavior when the popup was open. Task-number: QTBUG-61348 Change-Id: Ic0295db609495ccefbccb7c425a817926786014e Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--src/quicktemplates2/qquickcombobox.cpp11
-rw-r--r--tests/auto/controls/data/tst_combobox.qml54
2 files changed, 62 insertions, 3 deletions
diff --git a/src/quicktemplates2/qquickcombobox.cpp b/src/quicktemplates2/qquickcombobox.cpp
index 74efb6bb..3639bf2f 100644
--- a/src/quicktemplates2/qquickcombobox.cpp
+++ b/src/quicktemplates2/qquickcombobox.cpp
@@ -581,9 +581,14 @@ void QQuickComboBoxPrivate::setHighlightedIndex(int index, Highlighting highligh
void QQuickComboBoxPrivate::keySearch(const QString &text)
{
- int index = match(currentIndex + 1, text, Qt::MatchStartsWith | Qt::MatchWrap);
- if (index != -1)
- setCurrentIndex(index, Activate);
+ const int startIndex = isPopupVisible() ? highlightedIndex : currentIndex;
+ const int index = match(startIndex + 1, text, Qt::MatchStartsWith | Qt::MatchWrap);
+ if (index != -1) {
+ if (isPopupVisible())
+ setHighlightedIndex(index, Highlight);
+ else
+ setCurrentIndex(index, Activate);
+ }
}
int QQuickComboBoxPrivate::match(int start, const QString &text, Qt::MatchFlags flags) const
diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml
index 5389a04a..30d6a93c 100644
--- a/tests/auto/controls/data/tst_combobox.qml
+++ b/tests/auto/controls/data/tst_combobox.qml
@@ -629,36 +629,90 @@ TestCase {
compare(control.currentIndex, 0)
compare(control.currentText, "Banana")
+ compare(control.highlightedIndex, -1)
keyPress(Qt.Key_C)
compare(control.currentIndex, 1)
compare(control.currentText, "Coco")
+ compare(control.highlightedIndex, -1)
// no match
keyPress(Qt.Key_N)
compare(control.currentIndex, 1)
compare(control.currentText, "Coco")
+ compare(control.highlightedIndex, -1)
keyPress(Qt.Key_C)
compare(control.currentIndex, 2)
compare(control.currentText, "Coconut")
+ compare(control.highlightedIndex, -1)
keyPress(Qt.Key_C)
compare(control.currentIndex, 4)
compare(control.currentText, "Cocomuffin")
+ compare(control.highlightedIndex, -1)
// wrap
keyPress(Qt.Key_C)
compare(control.currentIndex, 1)
compare(control.currentText, "Coco")
+ compare(control.highlightedIndex, -1)
keyPress(Qt.Key_A)
compare(control.currentIndex, 3)
compare(control.currentText, "Apple")
+ compare(control.highlightedIndex, -1)
keyPress(Qt.Key_B)
compare(control.currentIndex, 0)
compare(control.currentText, "Banana")
+ compare(control.highlightedIndex, -1)
+
+ // popup
+ control.popup.open()
+ tryCompare(control.popup, "opened", true)
+
+ compare(control.currentIndex, 0)
+ compare(control.highlightedIndex, 0)
+
+ keyClick(Qt.Key_C)
+ compare(control.highlightedIndex, 1) // "Coco"
+ compare(control.currentIndex, 0)
+
+ // no match
+ keyClick(Qt.Key_N)
+ compare(control.highlightedIndex, 1)
+ compare(control.currentIndex, 0)
+
+ keyClick(Qt.Key_C)
+ compare(control.highlightedIndex, 2) // "Coconut"
+ compare(control.currentIndex, 0)
+
+ keyClick(Qt.Key_C)
+ compare(control.highlightedIndex, 4) // "Cocomuffin"
+ compare(control.currentIndex, 0)
+
+ // wrap
+ keyClick(Qt.Key_C)
+ compare(control.highlightedIndex, 1) // "Coco"
+ compare(control.currentIndex, 0)
+
+ keyClick(Qt.Key_B)
+ compare(control.highlightedIndex, 0) // "Banana"
+ compare(control.currentIndex, 0)
+
+ keyClick(Qt.Key_A)
+ compare(control.highlightedIndex, 3) // "Apple"
+ compare(control.currentIndex, 0)
+
+ verify(control.popup.visible)
+
+ // accept
+ keyClick(Qt.Key_Return)
+ tryCompare(control.popup, "visible", false)
+ compare(control.currentIndex, 3)
+ compare(control.currentText, "Apple")
+ compare(control.highlightedIndex, -1)
}
function test_popup() {