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

Continue to implement search

parent a90ecbd9
Pipeline #139000 passed with stages
in 5 minutes and 7 seconds
......@@ -8,6 +8,7 @@
#include "textfindreplacewidget.h"
#include <QLineEdit>
#include <QPlainTextEdit>
#include <QRegularExpression>
#include <QTextCursor>
#include <QTextDocument>
......@@ -36,25 +37,27 @@ int FindUtils::replaceAll(QTextDocument *document, const TextFindWidget *findWid
c.endEditBlock();
return count;
}
bool FindUtils::find(QTextDocument *document, const TextFindWidget *findWidget)
#include <QDebug>
bool FindUtils::find(QPlainTextEdit *view, const TextFindWidget *findWidget)
{
// Step 1: search without modify text
// Step 2: use FindUtils::normalize
QTextCursor c(document);
// if (document->find())
const QString text = FindUtils::normalize(document->toPlainText());
const QString text = FindUtils::normalize(view->document()->toPlainText());
QTextDocument doc(text);
QTextCursor c(&doc);
QTextCursor docCusor(view->textCursor());
c.setPosition(docCusor.position());
qDebug() << " docCusor.position() " << docCusor.position();
QTextDocument::FindFlags flags = findWidget->searchOptions() & ~QTextDocument::FindBackward;
if (findWidget->isRegularExpression()) {
c = document->find(findWidget->searchRegularExpression(), c, flags);
c = doc.find(FindUtils::normalize(findWidget->searchText()), c, flags);
} else {
c = document->find(findWidget->searchText(), c, flags);
c = doc.find(FindUtils::normalize(findWidget->searchText()), c, flags);
}
doc.find(findWidget->searchText(), c, flags);
if (!c.isNull()) {
// setTextCursor(search);
qDebug() << " c.selectionStart() " << c.selectionStart() << "c.selectionEnd() " << c.selectionEnd();
docCusor.setPosition(c.selectionStart());
docCusor.setPosition(c.selectionEnd(), QTextCursor::KeepAnchor);
view->setTextCursor(docCusor);
view->ensureCursorVisible();
return true;
}
return false;
......
......@@ -10,7 +10,7 @@
#include <QStringView>
#include <qglobal.h>
class QTextDocument;
class QPlainTextEdit;
namespace KPIMTextEdit
{
class TextFindWidget;
......@@ -28,7 +28,7 @@ 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(QTextDocument *document, const TextFindWidget *findWidget);
Q_REQUIRED_RESULT bool find(QPlainTextEdit *view, const TextFindWidget *findWidget);
}
} // namespace KPIMTextEdit
......@@ -15,7 +15,7 @@
#include <QRegularExpression>
using namespace KPIMTextEdit;
// #define SEARCH_DIACRITIC_WORD 1
#define SEARCH_DIACRITIC_WORD 1
class KPIMTextEdit::PlainTextEditFindBarPrivate
{
public:
......@@ -54,7 +54,10 @@ bool PlainTextEditFindBar::documentIsEmpty() const
bool PlainTextEditFindBar::searchInDocument(const QString &text, QTextDocument::FindFlags searchOptions)
{
#ifdef SEARCH_DIACRITIC_WORD
const bool found = d->mView->find(FindUtils::normalize(text), searchOptions);
// bool found = d->mView->find(text, searchOptions);
// if (!found) {
bool found = FindUtils::find(d->mView, mFindWidget);
//}
#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