diff --git a/src/plugins/coreplugin/locator/locatorwidget.cpp b/src/plugins/coreplugin/locator/locatorwidget.cpp index 2d0f546f108..09c1f331bce 100644 --- a/src/plugins/coreplugin/locator/locatorwidget.cpp +++ b/src/plugins/coreplugin/locator/locatorwidget.cpp @@ -72,6 +72,9 @@ const int LocatorEntryRole = int(HighlightingItemRole::User); namespace Core { namespace Internal { +QFuture LocatorWidget::m_sharedFuture; +LocatorWidget *LocatorWidget::m_sharedFutureOrigin = nullptr; + /* A model to represent the Locator results. */ class LocatorModel : public QAbstractListModel { @@ -839,13 +842,23 @@ void LocatorWidget::updateCompletionList(const QString &text) return; m_updateRequested = true; - if (m_entriesWatcher->future().isRunning()) { + if (m_sharedFuture.isRunning()) { // Cancel the old future. We may not just block the UI thread to wait for the search to - // actually cancel, so try again when the finshed signal of the watcher ends up in - // updateEntries() (which will call updateCompletionList again with the - // requestedCompletionText) + // actually cancel. m_requestedCompletionText = text; - m_entriesWatcher->future().cancel(); + if (m_sharedFutureOrigin == this) { + // This locator widget is currently running. Make handleSearchFinished trigger another + // update. + m_rerunAfterFinished = true; + } else { + // Another locator widget is running. Trigger another update when that is finished. + Utils::onFinished(m_sharedFuture, this, [this](const QFuture &) { + const QString text = m_requestedCompletionText; + m_requestedCompletionText.clear(); + updateCompletionList(text); + }); + } + m_sharedFuture.cancel(); return; } @@ -857,6 +870,8 @@ void LocatorWidget::updateCompletionList(const QString &text) for (ILocatorFilter *filter : filters) filter->prepareSearch(searchText); QFuture future = Utils::runAsync(&runSearch, filters, searchText); + m_sharedFuture = QFuture(future); + m_sharedFutureOrigin = this; m_entriesWatcher->setFuture(future); } @@ -870,7 +885,8 @@ void LocatorWidget::handleSearchFinished() m_rowRequestedForAccept.reset(); return; } - if (m_entriesWatcher->future().isCanceled()) { + if (m_rerunAfterFinished) { + m_rerunAfterFinished = false; const QString text = m_requestedCompletionText; m_requestedCompletionText.clear(); updateCompletionList(text); diff --git a/src/plugins/coreplugin/locator/locatorwidget.h b/src/plugins/coreplugin/locator/locatorwidget.h index 5fa538ec0b7..38ff7585add 100644 --- a/src/plugins/coreplugin/locator/locatorwidget.h +++ b/src/plugins/coreplugin/locator/locatorwidget.h @@ -97,10 +97,13 @@ private: Utils::FancyLineEdit *m_fileLineEdit = nullptr; QTimer m_showPopupTimer; QFutureWatcher *m_entriesWatcher = nullptr; + static QFuture m_sharedFuture; + static LocatorWidget *m_sharedFutureOrigin; QString m_requestedCompletionText; bool m_shuttingDown = false; bool m_needsClearResult = true; bool m_updateRequested = false; + bool m_rerunAfterFinished = false; bool m_possibleToolTipRequest = false; QWidget *m_progressIndicator = nullptr; QTimer m_showProgressTimer;