Commit 1c9e0372 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Simplify code

parent ab5d03ce
Pipeline #139190 passed with stages
in 2 minutes and 36 seconds
......@@ -40,7 +40,7 @@ int FindUtils::replaceAll(QTextDocument *document, const TextFindWidget *findWid
return count;
}
bool FindUtils::find(QPlainTextEdit *view, const TextFindWidget *findWidget)
bool FindUtils::find(QPlainTextEdit *view, const QString &searchText, QTextDocument::FindFlags searchOptions)
{
const QString text = FindUtils::normalize(view->document()->toPlainText());
QTextDocument doc(text);
......@@ -48,12 +48,7 @@ bool FindUtils::find(QPlainTextEdit *view, const TextFindWidget *findWidget)
QTextCursor docCusor(view->textCursor());
c.setPosition(docCusor.position());
qDebug() << " docCusor.position() " << docCusor.position();
QTextDocument::FindFlags flags = findWidget->searchOptions() & ~QTextDocument::FindBackward;
if (findWidget->isRegularExpression()) {
c = doc.find(FindUtils::normalize(findWidget->searchText()), c, flags);
} else {
c = doc.find(FindUtils::normalize(findWidget->searchText()), c, flags);
}
c = doc.find(FindUtils::normalize(searchText), c, searchOptions);
if (!c.isNull()) {
qDebug() << " c.selectionStart() " << c.selectionStart() << "c.selectionEnd() " << c.selectionEnd();
docCusor.setPosition(c.selectionStart());
......@@ -65,7 +60,7 @@ bool FindUtils::find(QPlainTextEdit *view, const TextFindWidget *findWidget)
return false;
}
bool FindUtils::find(QTextEdit *view, const TextFindWidget *findWidget)
bool FindUtils::find(QTextEdit *view, const QString &searchText, QTextDocument::FindFlags searchOptions)
{
const QString text = FindUtils::normalize(view->document()->toPlainText());
QTextDocument doc(text);
......@@ -73,12 +68,7 @@ bool FindUtils::find(QTextEdit *view, const TextFindWidget *findWidget)
QTextCursor docCusor(view->textCursor());
c.setPosition(docCusor.position());
qDebug() << " docCusor.position() " << docCusor.position();
QTextDocument::FindFlags flags = findWidget->searchOptions() & ~QTextDocument::FindBackward;
if (findWidget->isRegularExpression()) {
c = doc.find(FindUtils::normalize(findWidget->searchText()), c, flags);
} else {
c = doc.find(FindUtils::normalize(findWidget->searchText()), c, flags);
}
c = doc.find(FindUtils::normalize(searchText), c, searchOptions);
if (!c.isNull()) {
qDebug() << " c.selectionStart() " << c.selectionStart() << "c.selectionEnd() " << c.selectionEnd();
docCusor.setPosition(c.selectionStart());
......
......@@ -8,8 +8,8 @@
#include <QChar>
#include <QStringView>
#include <QTextDocument>
#include <qglobal.h>
class QTextDocument;
class QPlainTextEdit;
class QTextEdit;
namespace KPIMTextEdit
......@@ -29,8 +29,8 @@ Q_REQUIRED_RESULT int replaceAll(QTextDocument *document, const TextFindWidget *
Q_REQUIRED_RESULT QString normalize(QStringView str);
Q_REQUIRED_RESULT QChar normalize(QChar c);
Q_REQUIRED_RESULT bool find(QPlainTextEdit *view, const TextFindWidget *findWidget);
Q_REQUIRED_RESULT bool find(QTextEdit *view, const TextFindWidget *findWidget);
Q_REQUIRED_RESULT bool find(QPlainTextEdit *view, const QString &searchText, QTextDocument::FindFlags searchOptions);
Q_REQUIRED_RESULT bool find(QTextEdit *view, const QString &searchText, QTextDocument::FindFlags searchOptions);
}
} // namespace KPIMTextEdit
......@@ -54,7 +54,7 @@ bool PlainTextEditFindBar::documentIsEmpty() const
bool PlainTextEditFindBar::searchInDocument(const QString &text, QTextDocument::FindFlags searchOptions)
{
#ifdef SEARCH_DIACRITIC_WORD
const bool found = FindUtils::find(d->mView, mFindWidget);
const bool found = FindUtils::find(d->mView, text, searchOptions);
#else
const bool found = d->mView->find(text, searchOptions);
#endif
......
......@@ -54,7 +54,7 @@ bool RichTextEditFindBar::documentIsEmpty() const
bool RichTextEditFindBar::searchInDocument(const QString &text, QTextDocument::FindFlags searchOptions)
{
#ifdef SEARCH_DIACRITIC_WORD
const bool found = FindUtils::find(d->mView, mFindWidget);
const bool found = FindUtils::find(d->mView, text, searchOptions);
#else
const bool found = d->mView->find(text, searchOptions);
#endif
......
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