MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / _replace

Method _replace

editor/gui/code_editor.cpp:250–298  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

248}
249
250void FindReplaceBar::_replace() {
251 text_editor->begin_complex_operation();
252 text_editor->remove_secondary_carets();
253 bool selection_enabled = text_editor->has_selection(0);
254 Point2i selection_begin, selection_end;
255 if (selection_enabled) {
256 selection_begin = Point2i(text_editor->get_selection_from_line(0), text_editor->get_selection_from_column(0));
257 selection_end = Point2i(text_editor->get_selection_to_line(0), text_editor->get_selection_to_column(0));
258 }
259
260 String repl_text = get_replace_text();
261 int search_text_len = get_search_text().length();
262
263 if (selection_enabled && is_selection_only()) {
264 // Restrict search_current() to selected region.
265 text_editor->set_caret_line(selection_begin.width, false, true, -1, 0);
266 text_editor->set_caret_column(selection_begin.height, true, 0);
267 }
268
269 if (search_current()) {
270 text_editor->unfold_line(result_line);
271 text_editor->select(result_line, result_col, result_line, result_col + search_text_len, 0);
272
273 if (selection_enabled && is_selection_only()) {
274 Point2i match_from(result_line, result_col);
275 Point2i match_to(result_line, result_col + search_text_len);
276 if (!(match_from < selection_begin || match_to > selection_end)) {
277 text_editor->insert_text_at_caret(repl_text, 0);
278 if (match_to.x == selection_end.x) {
279 // Adjust selection bounds if necessary.
280 selection_end.y += repl_text.length() - search_text_len;
281 }
282 }
283 } else {
284 text_editor->insert_text_at_caret(repl_text, 0);
285 }
286 }
287 text_editor->end_complex_operation();
288 results_count = -1;
289 results_count_to_current = -1;
290 needs_to_count_results = true;
291
292 if (selection_enabled && is_selection_only()) {
293 // Reselect in order to keep 'Replace' restricted to selection.
294 text_editor->select(selection_begin.x, selection_begin.y, selection_end.x, selection_end.y, 0);
295 } else {
296 text_editor->deselect(0);
297 }
298}
299
300void FindReplaceBar::_replace_all() {
301 text_editor->begin_complex_operation();

Callers

nothing calls this directly

Calls 15

get_selection_to_lineMethod · 0.80
set_caret_lineMethod · 0.80
unfold_lineMethod · 0.80
end_complex_operationMethod · 0.80
has_selectionMethod · 0.45
lengthMethod · 0.45
set_caret_columnMethod · 0.45

Tested by

no test coverage detected