@@ -153,21 +153,30 @@ bool mbServerScriptEditor::findText(const QString &text, int findFlags)
153153 return this ->find (text, tFindFlags);
154154}
155155
156- bool mbServerScriptEditor::replaceText (const QString &replacement)
156+ bool mbServerScriptEditor::replaceText (const QString &text, const QString & replacement, int findFlags )
157157{
158158 QTextCursor cursor = textCursor ();
159159 if (!cursor.hasSelection ())
160+ {
161+ findText (text, findFlags);
160162 return false ;
163+ }
161164
162165 // Store selected text before replacement
163166 QString selectedText = cursor.selectedText ();
167+ if (text != selectedText)
168+ {
169+ findText (text, findFlags);
170+ return false ;
171+ }
164172
165173 // Replace current selection
166174 cursor.insertText (replacement);
167175
168176 // Move to the next occurrence
177+ QTextDocument::FindFlags tFindFlags = toQTextDocumentFindFlags (findFlags);
169178 QTextDocument *doc = document ();
170- QTextCursor next = doc->find (selectedText, cursor);
179+ QTextCursor next = doc->find (selectedText, cursor, tFindFlags );
171180
172181 if (next.isNull ())
173182 return true ;
@@ -177,16 +186,9 @@ bool mbServerScriptEditor::replaceText(const QString &replacement)
177186 return true ;
178187}
179188
180- bool mbServerScriptEditor::replaceTextAll (const QString &replacement)
189+ bool mbServerScriptEditor::replaceTextAll (const QString &text, const QString & replacement, int findFlags )
181190{
182- QTextCursor cursor = textCursor ();
183- if (!cursor.hasSelection ())
184- return false ;
185-
186- QString selectedText = cursor.selectedText ();
187- if (selectedText.isEmpty ())
188- return false ;
189-
191+ QTextDocument::FindFlags tFindFlags = toQTextDocumentFindFlags (findFlags);
190192 moveCursor (QTextCursor::Start);
191193 bool replaced = false ;
192194
@@ -207,7 +209,7 @@ bool mbServerScriptEditor::replaceTextAll(const QString &replacement)
207209 */
208210
209211 this ->textCursor ().beginEditBlock ();
210- while (this ->find (selectedText ))
212+ while (this ->find (text, tFindFlags ))
211213 {
212214 this ->textCursor ().insertText (replacement);
213215 replaced = true ;
0 commit comments