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,51 @@ 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("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); + 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 @@ -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& strNotUsed = curEntity->text(); + int len = stringLengthAdaptedWithHyphen(strNotUsed, it, m_words.constEnd()); + const QString str = QString(strNotUsed).replace('\n', ' '); if (offset >= len) { @@ -980,8 +981,9 @@ } const TinyTextEntity* curEntity = *it; - const QString& str = curEntity->text(); - int len = stringLengthAdaptedWithHyphen(str, it, m_words.constEnd()); + const QString& strNotUsed = curEntity->text(); + int len = stringLengthAdaptedWithHyphen(strNotUsed, it, m_words.constEnd()); + const QString str = QString(strNotUsed).replace('\n', ' '); if (offset <= 0) {