diff options
author | Samuel Gaist <samuel.gaist@edeltech.ch> | 2015-09-27 01:22:42 +0200 |
---|---|---|
committer | Samuel Gaist <samuel.gaist@edeltech.ch> | 2016-08-28 15:18:55 +0000 |
commit | e52fcb7dc78c83586c813f55f087a98bae4eaa0e (patch) | |
tree | b397eb7566d464b28275e52d03f36be4e6646dcb | |
parent | 2743cd54a0785b6c8d16b570643281ef61024936 (diff) |
QTextDocument: fix string backward search
[ChangeLog][QtGui][QTextDocument] Fixed a bug that would return a wrong
position when searching backward from the end of the document.
Task-number: QTBUG-48182
Change-Id: I6e88f808a50cb840f61e7bc579e2a28c5300089d
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r-- | src/gui/text/qtextdocument.cpp | 2 | ||||
-rw-r--r-- | tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp | 2 |
2 files changed, 3 insertions, 1 deletions
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index 3edf652f35..6cccf417c7 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -1309,7 +1309,7 @@ QTextCursor QTextDocument::find(const QString &subString, int from, FindFlags op //do not include the character given in the position. if (options & FindBackward) { --pos ; - if (pos < subString.size()) + if (pos < 0) return QTextCursor(); } diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp index 02e2bf27e2..bb20d99e30 100644 --- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp @@ -323,6 +323,8 @@ void tst_QTextDocument::find_data() << 15 << 6 << 11; QTest::newRow("nbsp") << "Hello" + QString(QChar(QChar::Nbsp)) +"World" << " " << int(QTextDocument::FindCaseSensitively) << 0 << 5 << 6; + + QTest::newRow("from-the-end") << "Hello World" << "Hello World" << int(QTextDocument::FindCaseSensitively| QTextDocument::FindBackward) << 11 << 0 << 11; } void tst_QTextDocument::find() |