Commit 558a19ba authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Prepare autotest

parent 532adacc
Pipeline #143951 passed with stages
in 2 minutes and 28 seconds
......@@ -31,8 +31,29 @@ QTextDocument::FindFlags FindUtils::convertTextEditFindFlags(TextEditFindBarBase
return flags;
}
int FindUtils::replaceAll(QTextDocument *document, const QString &str, const QString &replaceWidget, QTextDocument::FindFlags searchOptions)
int FindUtils::replaceAll(QTextEdit *view, const QString &str, const QString &replaceWidget, QTextDocument::FindFlags searchOptions)
{
auto document = view->document();
QTextCursor c(document);
c.beginEditBlock();
int count = 0;
// Ignoring FindBackward when replacing all
const QTextDocument::FindFlags flags = searchOptions & ~QTextDocument::FindBackward;
while (!c.isNull()) {
c = document->find(str, c, flags);
if (!c.isNull()) {
// find() selects found text, and insertText() replaces selection
c.insertText(replaceWidget);
count++;
}
}
c.endEditBlock();
return count;
}
int FindUtils::replaceAll(QPlainTextEdit *view, const QString &str, const QString &replaceWidget, QTextDocument::FindFlags searchOptions)
{
auto document = view->document();
QTextCursor c(document);
c.beginEditBlock();
int count = 0;
......
......@@ -27,7 +27,8 @@ namespace FindUtils
*
* @return number of replacements done
*/
Q_REQUIRED_RESULT int replaceAll(QTextDocument *document, const QString &str, const QString &replaceWidget, QTextDocument::FindFlags searchOptions);
Q_REQUIRED_RESULT int replaceAll(QPlainTextEdit *view, const QString &str, const QString &replaceWidget, QTextDocument::FindFlags searchOptions);
Q_REQUIRED_RESULT int replaceAll(QTextEdit *view, const QString &str, const QString &replaceWidget, QTextDocument::FindFlags searchOptions);
Q_REQUIRED_RESULT int
replaceAll(QTextDocument *document, const QRegularExpression &regExp, const QString &replaceWidget, QTextDocument::FindFlags searchOptions);
Q_REQUIRED_RESULT QString normalize(QStringView str);
......
......@@ -117,7 +117,7 @@ void PlainTextEditFindBar::slotReplaceAllText()
if (mFindWidget->isRegularExpression()) {
count = FindUtils::replaceAll(d->mView->document(), mFindWidget->searchRegularExpression(), replaceStr, searchOptions);
} else {
count = FindUtils::replaceAll(d->mView->document(), mFindWidget->searchText(), replaceStr, searchOptions);
count = FindUtils::replaceAll(d->mView, mFindWidget->searchText(), replaceStr, searchOptions);
}
Q_EMIT displayMessageIndicator(i18np("%1 replacement made", "%1 replacements made", count));
}
......@@ -107,7 +107,7 @@ void RichTextEditFindBar::slotReplaceAllText()
if (mFindWidget->isRegularExpression()) {
count = FindUtils::replaceAll(d->mView->document(), mFindWidget->searchRegularExpression(), replaceStr, searchOptions);
} else {
count = FindUtils::replaceAll(d->mView->document(), mFindWidget->searchText(), replaceStr, searchOptions);
count = FindUtils::replaceAll(d->mView, mFindWidget->searchText(), replaceStr, searchOptions);
}
Q_EMIT displayMessageIndicator(i18np("%1 replacement made", "%1 replacements made", count));
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment