Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
KPimTextEdit
Commits
1c72b524
Commit
1c72b524
authored
Feb 17, 2022
by
Laurent Montel
😁
Browse files
Continue to implement search
parent
a90ecbd9
Pipeline
#139000
passed with stages
in 5 minutes and 7 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/texteditor/commonwidget/findutils.cpp
View file @
1c72b524
...
...
@@ -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
(
Q
TextDocument
*
document
,
const
TextFindWidget
*
findWidget
)
#include <QDebug>
bool
FindUtils
::
find
(
Q
PlainTextEdit
*
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
=
doc
ument
->
find
(
findWidget
->
search
RegularExpression
(
),
c
,
flags
);
c
=
doc
.
find
(
FindUtils
::
normalize
(
findWidget
->
search
Text
()
),
c
,
flags
);
}
else
{
c
=
doc
ument
->
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
;
...
...
src/texteditor/commonwidget/findutils.h
View file @
1c72b524
...
...
@@ -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
(
Q
TextDocument
*
document
,
const
TextFindWidget
*
findWidget
);
Q_REQUIRED_RESULT
bool
find
(
Q
PlainTextEdit
*
view
,
const
TextFindWidget
*
findWidget
);
}
}
// namespace KPIMTextEdit
src/texteditor/plaintexteditor/plaintexteditfindbar.cpp
View file @
1c72b524
...
...
@@ -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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment