Skip to content
GitLab
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
1d93ab93
Commit
1d93ab93
authored
Mar 03, 2022
by
Laurent Montel
Browse files
Fix replace all
parent
8fdee9d8
Pipeline
#144286
passed with stages
in 2 minutes and 27 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/texteditor/commonwidget/findutils.cpp
View file @
1d93ab93
...
...
@@ -33,6 +33,7 @@ QTextDocument::FindFlags FindUtils::convertTextEditFindFlags(TextEditFindBarBase
int
FindUtils
::
replaceAll
(
QTextEdit
*
view
,
const
QString
&
str
,
const
QString
&
replaceWidget
,
QTextDocument
::
FindFlags
searchOptions
)
{
qDebug
()
<<
" SSSSSSSSSSSSSSSSSSs"
;
auto
document
=
view
->
document
();
QTextCursor
c
(
document
);
c
.
beginEditBlock
();
...
...
@@ -44,18 +45,22 @@ int FindUtils::replaceAll(QTextEdit *view, const QString &str, const QString &re
if
(
!
c
.
isNull
())
{
// find() selects found text, and insertText() replaces selection
c
.
insertText
(
replaceWidget
);
qDebug
()
<<
" replaceWidget "
<<
replaceWidget
;
count
++
;
}
else
{
break
;
}
}
c
.
endEditBlock
();
view
->
setTextCursor
(
c
);
return
count
;
}
int
FindUtils
::
replaceAll
(
QPlainTextEdit
*
view
,
const
QString
&
str
,
const
QString
&
replaceStr
,
QTextDocument
::
FindFlags
searchOptions
)
{
auto
document
=
view
->
document
();
view
->
textCursor
().
beginEditBlock
();
QTextCursor
c
(
document
);
c
.
beginEditBlock
();
int
count
=
0
;
// Ignoring FindBackward when replacing all
const
QTextDocument
::
FindFlags
flags
=
searchOptions
&
~
QTextDocument
::
FindBackward
;
...
...
@@ -65,9 +70,11 @@ int FindUtils::replaceAll(QPlainTextEdit *view, const QString &str, const QStrin
// find() selects found text, and insertText() replaces selection
c
.
insertText
(
replaceStr
);
count
++
;
}
else
{
break
;
}
}
c
.
endEditBlock
();
view
->
textCursor
()
.
endEditBlock
();
return
count
;
}
...
...
@@ -84,6 +91,8 @@ int FindUtils::replaceAll(QTextDocument *document, const QRegularExpression ®
// find() selects found text, and insertText() replaces selection
c
.
insertText
(
replaceWidget
);
count
++
;
}
else
{
break
;
}
}
c
.
endEditBlock
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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