summaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/searchtextlocator.cpp
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2023-04-30 18:30:36 -0400
committerLibravatarUnit 193 <unit193@unit193.net>2023-04-30 18:30:36 -0400
commit3565aad630864ecdbe53fdaa501ea708555b3c7c (patch)
treec743e4ad0bad39ebdb2f514c7cc52d34a257ebbe /SQLiteStudio3/guiSQLiteStudio/searchtextlocator.cpp
parent1fdc150116cad39aae5c5da407c3312b47a59e3a (diff)
New upstream version 3.4.4+dfsg.upstream/3.4.4+dfsg
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/searchtextlocator.cpp')
-rw-r--r--SQLiteStudio3/guiSQLiteStudio/searchtextlocator.cpp41
1 files changed, 39 insertions, 2 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/searchtextlocator.cpp b/SQLiteStudio3/guiSQLiteStudio/searchtextlocator.cpp
index 7e5c2ec..ac93028 100644
--- a/SQLiteStudio3/guiSQLiteStudio/searchtextlocator.cpp
+++ b/SQLiteStudio3/guiSQLiteStudio/searchtextlocator.cpp
@@ -204,8 +204,45 @@ bool SearchTextLocator::replaceAndFind()
void SearchTextLocator::replaceAll()
{
- while (replaceAndFind())
- continue;
+ QString origContents = document->toPlainText();
+ QString contents = origContents;
+ Qt::CaseSensitivity cs = caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive;
+ int replLen = replaceString.length();
+ int diff = 0;
+ if (regularExpression)
+ {
+ QRegExp re(lookupString, cs);
+ contents.replace(re, replaceString);
+
+ int pos = 0;
+ while ((pos = re.indexIn(origContents, pos)) != -1 && pos < startPosition)
+ {
+ int len = re.matchedLength();
+ pos += len;
+ diff += (replLen - len);
+ }
+ }
+ else
+ {
+ contents.replace(lookupString, replaceString, cs);
+
+ int len = lookupString.length();
+ int singleDiff = (replLen - len);
+ int pos = 0;
+ while ((pos = origContents.indexOf(lookupString, pos, cs)) != -1 && pos < startPosition)
+ {
+ pos += len;
+ diff += singleDiff;
+ }
+ }
+ int newPos = startPosition + diff; // calculated before replacing contents to use original startPosition
+
+ QTextCursor cursor(document);
+ cursor.setPosition(0);
+ cursor.setPosition(origContents.length(), QTextCursor::KeepAnchor);
+ cursor.insertText(contents);
+
+ emit newCursorPositionAfterAllReplaced(newPos);
}
void SearchTextLocator::cursorMoved()