From 1f3f15f01df64bea5b1e0217ebea456e9c84d311 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Mon, 18 Feb 2019 15:49:07 +0100 Subject: [PATCH] Search results: Open editor on pressing enter on file item Only do that on enter/return, not on double-click which also expands the item (we don't want double-click to do both). Task-number: QTCREATORBUG-18200 Change-Id: Ib4f939a76054832f12b84c8e4353b88e010f1126 Reviewed-by: David Schulz --- .../coreplugin/find/searchresulttreeview.cpp | 15 +++++++++++++++ .../coreplugin/find/searchresulttreeview.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/plugins/coreplugin/find/searchresulttreeview.cpp b/src/plugins/coreplugin/find/searchresulttreeview.cpp index 6a9b7067bf4..0ca09fcefd1 100644 --- a/src/plugins/coreplugin/find/searchresulttreeview.cpp +++ b/src/plugins/coreplugin/find/searchresulttreeview.cpp @@ -78,6 +78,21 @@ void SearchResultTreeView::addResults(const QList &items, Sear } } +void SearchResultTreeView::keyPressEvent(QKeyEvent *event) +{ + if ((event->key() == Qt::Key_Return + || event->key() == Qt::Key_Enter) + && event->modifiers() == 0 + && currentIndex().isValid() + && state() != QAbstractItemView::EditingState) { + const SearchResultItem item + = model()->data(currentIndex(), ItemDataRoles::ResultItemRole).value(); + emit jumpToSearchResult(item); + return; + } + TreeView::keyPressEvent(event); +} + void SearchResultTreeView::emitJumpToSearchResult(const QModelIndex &index) { if (model()->data(index, ItemDataRoles::IsGeneratedRole).toBool()) diff --git a/src/plugins/coreplugin/find/searchresulttreeview.h b/src/plugins/coreplugin/find/searchresulttreeview.h index 961940fe017..eb11d29a7d9 100644 --- a/src/plugins/coreplugin/find/searchresulttreeview.h +++ b/src/plugins/coreplugin/find/searchresulttreeview.h @@ -49,6 +49,8 @@ public: SearchResultTreeModel *model() const; void addResults(const QList &items, SearchResult::AddMode mode); + void keyPressEvent(QKeyEvent *event) override; + signals: void jumpToSearchResult(const SearchResultItem &item);