aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/find
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@digia.com>2013-01-03 15:44:35 +0100
committerDavid Schulz <david.schulz@digia.com>2013-01-08 10:58:19 +0100
commita7323614a09f341b5ef4fe9f359204658b930cc2 (patch)
tree24a99de44fed02167ef6dca29b73e2a9099ef049 /src/plugins/find
parent29a93998df8405e8799ad23934a56cd99fb36403 (diff)
Editor: Fixed endless loop in BaseTextFind
...when trying to replace some regular expressions that could result in empty search results like ^, $ or \b. Task-number: QTCREATORBUG-8464 Change-Id: I91a304d3609c3ec20437c698d53e6a1819dfb924 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
Diffstat (limited to 'src/plugins/find')
-rw-r--r--src/plugins/find/basetextfind.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/plugins/find/basetextfind.cpp b/src/plugins/find/basetextfind.cpp
index 5bcdb2835f5..df55f136c94 100644
--- a/src/plugins/find/basetextfind.cpp
+++ b/src/plugins/find/basetextfind.cpp
@@ -264,9 +264,23 @@ int BaseTextFind::replaceAll(const QString &before, const QString &after,
regexp.setPatternSyntax(usesRegExp ? QRegExp::RegExp : QRegExp::FixedString);
regexp.setCaseSensitivity((findFlags & Find::FindCaseSensitively) ? Qt::CaseSensitive : Qt::CaseInsensitive);
QTextCursor found = findOne(regexp, editCursor, Find::textDocumentFlagsForFindFlags(findFlags));
- while (!found.isNull()
- && (found.selectionStart() < found.selectionEnd() || after.length() > 0)
- && inScope(found.selectionStart(), found.selectionEnd())) {
+ bool first = true;
+ while (!found.isNull() && inScope(found.selectionStart(), found.selectionEnd())) {
+ if (found == editCursor && !first) {
+ if (editCursor.atEnd())
+ break;
+ // If the newly found QTextCursor is the same as recently edit one we have to move on,
+ // otherwise we would run into an endless loop for some regular expressions
+ // like ^ or \b.
+ QTextCursor newPosCursor = editCursor;
+ newPosCursor.movePosition(findFlags & Find::FindBackward ?
+ QTextCursor::PreviousCharacter :
+ QTextCursor::NextCharacter);
+ found = findOne(regexp, newPosCursor, Find::textDocumentFlagsForFindFlags(findFlags));
+ continue;
+ }
+ if (first)
+ first = false;
++count;
editCursor.setPosition(found.selectionStart());
editCursor.setPosition(found.selectionEnd(), QTextCursor::KeepAnchor);