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>
This commit is contained in:
parent
2743cd54a0
commit
e52fcb7dc7
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user