Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 7f62b5f4 authored by Laurent Montel's avatar Laurent Montel 😁

Improve regular expression search

parent d5934729
......@@ -19,7 +19,7 @@
#include "texteditfindbarbase.h"
#include "texteditor/commonwidget/textfindreplacewidget.h"
#include "kpimtextedit_debug.h"
#include <QIcon>
#include <KLocalizedString>
#include <kmessagebox.h>
......@@ -176,7 +176,12 @@ bool TextEditFindBarBase::searchText(bool backward, bool isAutoSearch)
clearSelections();
}
const bool found = searchInDocument(mLastSearchStr, searchOptions);
bool found = false;
if (mFindWidget->isRegularExpression()) {
found = searchInDocument(mLastSearchRegExp, searchOptions);
} else {
found = searchInDocument(mLastSearchStr, searchOptions);
}
mFindWidget->setFoundMatch(found);
messageInfo(backward, isAutoSearch, found);
return found;
......@@ -196,7 +201,12 @@ void TextEditFindBarBase::slotUpdateSearchOptions()
{
const QTextDocument::FindFlags searchOptions = mFindWidget->searchOptions();
mLastSearchStr = mFindWidget->search()->text();
searchInDocument(mLastSearchStr, searchOptions);
mLastSearchRegExp = mFindWidget->searchRegExp();
if (mFindWidget->isRegularExpression()) {
searchInDocument(mLastSearchRegExp, searchOptions);
} else {
searchInDocument(mLastSearchStr, searchOptions);
}
}
void TextEditFindBarBase::clearSelections()
......
......@@ -79,6 +79,7 @@ private Q_SLOTS:
protected:
QString mLastSearchStr;
QRegExp mLastSearchRegExp;
TextFindWidget *mFindWidget = nullptr;
TextReplaceWidget *mReplaceWidget = nullptr;
bool mHideWhenClose = true;
......
......@@ -179,6 +179,17 @@ bool TextFindWidget::isRegularExpression() const
return mRegExpAct->isChecked();
}
QRegExp TextFindWidget::searchRegExp() const
{
QRegExp reg;
if (mCaseSensitiveAct->isChecked()) {
reg.setCaseSensitivity(Qt::CaseInsensitive);
}
//TODO QTextDocument::FindWholeWords ?
reg.setPattern(mSearch->text());
return reg;
}
QTextDocument::FindFlags TextFindWidget::searchOptions() const
{
QTextDocument::FindFlags opt = nullptr;
......
......@@ -43,6 +43,8 @@ public:
bool isRegularExpression() const;
QRegExp searchRegExp() const;
private Q_SLOTS:
void slotAutoSearch(const QString &str);
......
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