7#include "plaintexteditfindbar.h"
8#include "widgets/findutils.h"
9#include "widgets/textfindreplacewidget.h"
11#include <KLocalizedString>
12#include <TextUtils/ConvertText>
15#include <QPlainTextEdit>
16#include <QRegularExpression>
18using namespace TextCustomEditor;
19class TextCustomEditor::PlainTextEditFindBarPrivate
32 , d(new TextCustomEditor::PlainTextEditFindBarPrivate(view))
36PlainTextEditFindBar::~PlainTextEditFindBar() =
default;
38void PlainTextEditFindBar::slotSearchText(
bool backward,
bool isAutoSearch)
41 searchText(backward, isAutoSearch);
44bool PlainTextEditFindBar::viewIsReadOnly()
const
46 return d->mView->isReadOnly();
49bool PlainTextEditFindBar::documentIsEmpty()
const
51 return d->mView->document()->isEmpty();
57 if (searchOptions & TextEditFindBarBase::FindRespectDiacritics) {
58 found = d->mView->find(text, FindUtils::convertTextEditFindFlags(searchOptions));
60 found = FindUtils::find(d->mView, text, FindUtils::convertTextEditFindFlags(searchOptions));
62 mFindWidget->setFoundMatch(found);
68 const bool found = d->mView->find(regExp, FindUtils::convertTextEditFindFlags(searchOptions));
69 mFindWidget->setFoundMatch(found);
73void PlainTextEditFindBar::autoSearchMoveCursor()
77 d->mView->setTextCursor(
cursor);
80void PlainTextEditFindBar::slotReplaceText()
83 if (d->mView->textCursor().hasSelection()) {
84 if (mFindWidget->isRegularExpression()) {
85 if (d->mView->textCursor().selectedText().contains(mFindWidget->searchRegularExpression())) {
86 d->mView->textCursor().insertText(mReplaceWidget->replaceLineEdit()->
text());
88 searchText(
false,
false);
91 if (searchOptions & TextEditFindBarBase::FindRespectDiacritics) {
92 if (TextUtils::ConvertText::normalize(d->mView->textCursor().selectedText()) == TextUtils::ConvertText::normalize(mFindWidget->searchText())) {
93 d->mView->textCursor().insertText(mReplaceWidget->replaceLineEdit()->
text());
95 searchText(
false,
false);
97 if (d->mView->textCursor().selectedText() == mFindWidget->searchText()) {
98 d->mView->textCursor().insertText(mReplaceWidget->replaceLineEdit()->
text());
100 searchText(
false,
false);
106 searchText(
false,
false);
110void PlainTextEditFindBar::slotReplaceAllText()
113 const QString replaceStr{mReplaceWidget->replaceLineEdit()->
text()};
115 if (mFindWidget->isRegularExpression()) {
116 count = FindUtils::replaceAll(d->mView->document(), mFindWidget->searchRegularExpression(), replaceStr, searchOptions);
118 count = FindUtils::replaceAll(d->mView, mFindWidget->searchText(), replaceStr, searchOptions);
120 Q_EMIT displayMessageIndicator(
i18np(
"%1 replacement made",
"%1 replacements made", count));
123#include "moc_plaintexteditfindbar.cpp"
The TextEditFindBarBase class.
QString i18np(const char *singular, const char *plural, const TYPE &arg...)