Commit c1f643e3 authored by Eike Ziller's avatar Eike Ziller
Browse files

Fix search next/prev in search results.

Broke with ebb9e252



Change-Id: Ifb5821d4712e780df70bc1ec798123dd7b63b108
Reviewed-by: default avatarJarek Kobus <jaroslaw.kobus@nokia.com>
parent 0a59f347
......@@ -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;
......
......@@ -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;
......
......@@ -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()) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment