diff --git a/autotests/searchtest.cpp b/autotests/searchtest.cpp --- a/autotests/searchtest.cpp +++ b/autotests/searchtest.cpp @@ -48,6 +48,8 @@ void testHyphenAtEndOfPage(); void testOneColumn(); void testTwoColumns(); + void testAcrossMultipleLines_data(); + void testAcrossMultipleLines(); }; void SearchTest::initTestCase() @@ -423,5 +425,58 @@ delete page; } +void SearchTest::testAcrossMultipleLines_data() +{ + QTest::addColumn >("text"); + QTest::addColumn("searchString"); + QTest::addColumn("testCase"); + + QTest::newRow("Across Lines") << (QVector() << QStringLiteral("ab\na\nab\na, one more time, ab\na\nab\na")) << QStringLiteral("ab a ab a") << 1; + QTest::newRow("LineFeed search") << (QVector() << QStringLiteral("ab cd ab cd")) << QStringLiteral("ab\ncd") << 1; + QTest::newRow("LineFeed text") << (QVector() << QStringLiteral("ab\ncd ab\ncd")) << QStringLiteral("ab\ncd") << 1; + QTest::newRow("Tab text") << (QVector() << QStringLiteral("ab\tcd ab\tcd")) << QStringLiteral("ab cd") << 1; + QTest::newRow("Across Lines not find") << (QVector() << QStringLiteral("ab\naaa\nab\na")) << QStringLiteral("aba") << 2; + QTest::newRow("Hyphen doesn't count") << (QVector() << QStringLiteral("ab-\ncd")) << QStringLiteral("ab cd") << 2; +} + +void SearchTest::testAcrossMultipleLines() +{ + QFETCH(QVector, text); + QFETCH(QString, searchString); + QFETCH(int, testCase); + + QVector rect; \ + + for (int i = 0; i < text.size(); i++) { + rect << Okular::NormalizedRect(0.1*i, 0.0, 0.1*(i+1), 0.1); \ + } + + CREATE_PAGE; + + switch(testCase) + { + case 1: + TEST_NEXT_PREV(Okular::FromTop, true); + TEST_NEXT_PREV(Okular::NextResult, true); + TEST_NEXT_PREV(Okular::PreviousResult, true); + TEST_NEXT_PREV(Okular::NextResult, true); + TEST_NEXT_PREV(Okular::NextResult, false); + + TEST_NEXT_PREV(Okular::FromBottom, true); + TEST_NEXT_PREV(Okular::PreviousResult, true); + TEST_NEXT_PREV(Okular::PreviousResult, false); + break; + case 2: + TEST_NEXT_PREV(Okular::FromTop, false); + TEST_NEXT_PREV(Okular::NextResult, false); + + TEST_NEXT_PREV(Okular::FromBottom, false); + TEST_NEXT_PREV(Okular::PreviousResult, false); + break; + } + + delete page; +} + QTEST_MAIN( SearchTest ) #include "searchtest.moc" diff --git a/core/textpage.cpp b/core/textpage.cpp --- a/core/textpage.cpp +++ b/core/textpage.cpp @@ -846,7 +846,7 @@ const TextList::ConstIterator &end) { // normalize query search all unicode (including glyphs) - const QString query = _query.normalized(QString::NormalizationForm_KC); + const QString query = _query.normalized(QString::NormalizationForm_KC).replace(QRegExp("[\\s\n\r]+"), QString(' ')); // j is the current position in our query // len is the length of the string in TextEntity @@ -862,8 +862,9 @@ while ( it != end ) { const TinyTextEntity* curEntity = *it; - const QString& str = curEntity->text(); - int len = stringLengthAdaptedWithHyphen(str, it, m_words.constEnd()); + const QString& origStr = curEntity->text(); + const int len = stringLengthAdaptedWithHyphen(origStr, it, m_words.constEnd()); + const QString str = QString(origStr).replace(QRegExp("[\\s\n\r]+"), QString(' ')); if (offset >= len) { @@ -955,7 +956,7 @@ const TextList::ConstIterator &end) { // normalize query to search all unicode (including glyphs) - const QString query = _query.normalized(QString::NormalizationForm_KC); + const QString query = _query.normalized(QString::NormalizationForm_KC).replace(QRegExp("[\\s\n\r]+"), QString(' ')); // j is the current position in our query // len is the length of the string in TextEntity @@ -980,8 +981,9 @@ } const TinyTextEntity* curEntity = *it; - const QString& str = curEntity->text(); - int len = stringLengthAdaptedWithHyphen(str, it, m_words.constEnd()); + const QString& origStr = curEntity->text(); + const int len = stringLengthAdaptedWithHyphen(origStr, it, m_words.constEnd()); + const QString str = QString(origStr).replace(QRegExp("[\\s\n\r]+"), QString(' ')); if (offset <= 0) {