summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2017-07-17 10:36:24 +0200
committerEike Ziller <eike.ziller@qt.io>2017-07-17 11:06:09 +0000
commita7e895166f9ca6aad1389a46913b6c83bb3d76d0 (patch)
tree2cbe0ae68514866e194592dba9b8efb7122b900a /src
parentd5342eff77a3857e3d4341bef045e2ab01c73175 (diff)
downloadqt-creator-a7e895166f9ca6aad1389a46913b6c83bb3d76d0.tar.gz
Locator: Fix pressing return when no results are available yet
In that case the first item will be activated as soon as it gets available. That behavior got lost during the recent refactoring. Task-number: QTCREATORBUG-18560 Change-Id: Ifda117f92f2adf23b499f50bdb4809c5e7830517 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/coreplugin/locator/locatorwidget.cpp18
-rw-r--r--src/plugins/coreplugin/locator/locatorwidget.h4
2 files changed, 17 insertions, 5 deletions
diff --git a/src/plugins/coreplugin/locator/locatorwidget.cpp b/src/plugins/coreplugin/locator/locatorwidget.cpp
index 76f0ac1f5b..5073bcd33c 100644
--- a/src/plugins/coreplugin/locator/locatorwidget.cpp
+++ b/src/plugins/coreplugin/locator/locatorwidget.cpp
@@ -483,6 +483,16 @@ void CompletionList::keyPressEvent(QKeyEvent *event)
return;
}
break;
+ case Qt::Key_Return:
+ case Qt::Key_Enter:
+ // emit activated even if current index is not valid
+ // if there are no results yet, this allows activating the first entry when it is available
+ // (see LocatorWidget::addSearchResults)
+ if (event->modifiers() == 0) {
+ emit activated(currentIndex());
+ return;
+ }
+ break;
}
Utils::TreeView::keyPressEvent(event);
}
@@ -795,9 +805,9 @@ void LocatorWidget::handleSearchFinished()
m_showProgressTimer.stop();
setProgressIndicatorVisible(false);
m_updateRequested = false;
- if (m_rowRequestedForAccept >= 0) {
- acceptEntry(m_rowRequestedForAccept);
- m_rowRequestedForAccept = -1;
+ if (m_rowRequestedForAccept) {
+ acceptEntry(m_rowRequestedForAccept.value());
+ m_rowRequestedForAccept.reset();
return;
}
if (m_entriesWatcher->future().isCanceled()) {
@@ -892,7 +902,7 @@ void LocatorWidget::addSearchResults(int firstIndex, int endIndex)
m_locatorModel->addEntries(entries);
if (selectFirst) {
emit selectRow(0);
- if (m_rowRequestedForAccept >= 0)
+ if (m_rowRequestedForAccept)
m_rowRequestedForAccept = 0;
}
}
diff --git a/src/plugins/coreplugin/locator/locatorwidget.h b/src/plugins/coreplugin/locator/locatorwidget.h
index 4484faefdd..c4ce3c4a14 100644
--- a/src/plugins/coreplugin/locator/locatorwidget.h
+++ b/src/plugins/coreplugin/locator/locatorwidget.h
@@ -27,6 +27,8 @@
#include "locator.h"
+#include <utils/optional.h>
+
#include <QPointer>
#include <QWidget>
@@ -99,9 +101,9 @@ private:
bool m_needsClearResult = true;
bool m_updateRequested = false;
bool m_possibleToolTipRequest = false;
- int m_rowRequestedForAccept = -1;
QWidget *m_progressIndicator;
QTimer m_showProgressTimer;
+ Utils::optional<int> m_rowRequestedForAccept;
};
class LocatorPopup : public QWidget