diff --git a/src/plugins/find/searchresulttreemodel.cpp b/src/plugins/find/searchresulttreemodel.cpp index 95336e8a563a1fda9d45137ffe7dafffe08645a3..dc7f36995622e6156ca9b0ae419c8b543e0d0b7e 100644 --- a/src/plugins/find/searchresulttreemodel.cpp +++ b/src/plugins/find/searchresulttreemodel.cpp @@ -492,6 +492,13 @@ QModelIndex SearchResultTreeModel::prevIndex(const QModelIndex &idx, bool *wrapp return current; } +QModelIndex SearchResultTreeModel::followingIndex(const QModelIndex &idx, bool backward, bool includeGenerated, bool *wrapped) +{ + if (backward) + return prev(idx, includeGenerated, wrapped); + return next(idx, includeGenerated, wrapped); +} + QModelIndex SearchResultTreeModel::prev(const QModelIndex &idx, bool includeGenerated, bool *wrapped) const { QModelIndex value = idx; @@ -502,7 +509,8 @@ QModelIndex SearchResultTreeModel::prev(const QModelIndex &idx, bool includeGene } QModelIndex SearchResultTreeModel::find(const QRegExp &expr, const QModelIndex &index, - QTextDocument::FindFlags flags, bool *wrapped) + QTextDocument::FindFlags flags, + bool startWithCurrentIndex, bool *wrapped) { QModelIndex resultIndex; QModelIndex currentIndex = index; @@ -512,6 +520,8 @@ QModelIndex SearchResultTreeModel::find(const QRegExp &expr, const QModelIndex & bool anyWrapped = false; bool stepWrapped = false; + if (!startWithCurrentIndex) + currentIndex = followingIndex(currentIndex, backward, true, &stepWrapped); do { anyWrapped |= stepWrapped; // update wrapped state if we actually stepped to next/prev item if (currentIndex.isValid()) { @@ -519,10 +529,7 @@ QModelIndex SearchResultTreeModel::find(const QRegExp &expr, const QModelIndex & if (expr.indexIn(text) != -1) resultIndex = currentIndex; } - if (backward) - currentIndex = prev(currentIndex, true, &stepWrapped); - else - currentIndex = next(currentIndex, true, &stepWrapped); + currentIndex = followingIndex(currentIndex, backward, true, &stepWrapped); } while (!resultIndex.isValid() && currentIndex.isValid() && currentIndex != index); if (resultIndex.isValid() && wrapped) *wrapped = anyWrapped; @@ -530,7 +537,8 @@ QModelIndex SearchResultTreeModel::find(const QRegExp &expr, const QModelIndex & } QModelIndex SearchResultTreeModel::find(const QString &term, const QModelIndex &index, - QTextDocument::FindFlags flags, bool *wrapped) + QTextDocument::FindFlags flags, + bool startWithCurrentIndex, bool *wrapped) { QModelIndex resultIndex; QModelIndex currentIndex = index; @@ -541,6 +549,8 @@ QModelIndex SearchResultTreeModel::find(const QString &term, const QModelIndex & bool anyWrapped = false; bool stepWrapped = false; + if (!startWithCurrentIndex) + currentIndex = followingIndex(currentIndex, backward, true, &stepWrapped); do { anyWrapped |= stepWrapped; // update wrapped state if we actually stepped to next/prev item if (currentIndex.isValid()) { @@ -549,10 +559,7 @@ QModelIndex SearchResultTreeModel::find(const QString &term, const QModelIndex & if (!doc.find(term, 0, flags).isNull()) resultIndex = currentIndex; } - if (backward) - currentIndex = prev(currentIndex, true, &stepWrapped); - else - currentIndex = next(currentIndex, true, &stepWrapped); + currentIndex = followingIndex(currentIndex, backward, true, &stepWrapped); } while (!resultIndex.isValid() && currentIndex.isValid() && currentIndex != index); if (resultIndex.isValid() && wrapped) *wrapped = anyWrapped; diff --git a/src/plugins/find/searchresulttreemodel.h b/src/plugins/find/searchresulttreemodel.h index 40c2d789a1c92d7457decd372d95a888c2eac457..e01a869785cc65b9c39f536658c6511955c84b37 100644 --- a/src/plugins/find/searchresulttreemodel.h +++ b/src/plugins/find/searchresulttreemodel.h @@ -71,9 +71,9 @@ public: QList<QModelIndex> addResults(const QList<SearchResultItem> &items, SearchResult::AddMode mode); QModelIndex find(const QRegExp &expr, const QModelIndex &index, - QTextDocument::FindFlags flags, bool *wrapped = 0); + QTextDocument::FindFlags flags, bool startWithCurrentIndex, bool *wrapped = 0); QModelIndex find(const QString &term, const QModelIndex &index, - QTextDocument::FindFlags flags, bool *wrapped = 0); + QTextDocument::FindFlags flags, bool startWithCurrentIndex, bool *wrapped = 0); signals: void jumpToSearchResult(const QString &fileName, int lineNumber, @@ -90,6 +90,8 @@ private: bool setCheckState(const QModelIndex &idx, Qt::CheckState checkState, bool firstCall = true); QModelIndex nextIndex(const QModelIndex &idx, bool *wrapped = 0) const; QModelIndex prevIndex(const QModelIndex &idx, bool *wrapped = 0) const; + QModelIndex followingIndex(const QModelIndex &idx, bool backward, bool includeGenerated = false, + bool *wrapped = 0); SearchResultTreeItem *treeItemAtIndex(const QModelIndex &idx) const; SearchResultTreeItem *m_rootItem; diff --git a/src/plugins/find/searchresultwidget.cpp b/src/plugins/find/searchresultwidget.cpp index 34205ef4c7a1f6100870c876bfb6b21c70deac5a..556bd2409b531ab8d2f2acdfec939d7455d14e8b 100644 --- a/src/plugins/find/searchresultwidget.cpp +++ b/src/plugins/find/searchresultwidget.cpp @@ -117,7 +117,7 @@ public: } m_view->setCurrentIndex(m_incrementalFindStart); bool wrapped = false; - IFindSupport::Result result = find(txt, findFlags, &wrapped); + IFindSupport::Result result = find(txt, findFlags, true/*startFromCurrent*/, &wrapped); if (wrapped != m_incrementalWrappedState) { m_incrementalWrappedState = wrapped; showWrapIndicator(m_view); @@ -128,7 +128,7 @@ public: IFindSupport::Result findStep(const QString &txt, Find::FindFlags findFlags) { bool wrapped = false; - IFindSupport::Result result = find(txt, findFlags, &wrapped); + IFindSupport::Result result = find(txt, findFlags, false/*startFromNext*/, &wrapped); if (wrapped) showWrapIndicator(m_view); if (result == IFindSupport::Found) { @@ -138,7 +138,8 @@ public: return result; } - IFindSupport::Result find(const QString &txt, Find::FindFlags findFlags, bool *wrapped) + IFindSupport::Result find(const QString &txt, Find::FindFlags findFlags, + bool startFromCurrentIndex, bool *wrapped) { if (wrapped) *wrapped = false; @@ -150,11 +151,13 @@ public: index = m_view->model()->find(QRegExp(txt, (sensitive ? Qt::CaseSensitive : Qt::CaseInsensitive)), m_view->currentIndex(), Find::textDocumentFlagsForFindFlags(findFlags), + startFromCurrentIndex, wrapped); } else { index = m_view->model()->find(txt, m_view->currentIndex(), Find::textDocumentFlagsForFindFlags(findFlags), + startFromCurrentIndex, wrapped); } if (index.isValid()) {