| 298 | } |
| 299 | |
| 300 | void FindReplaceBar::_replace_all() { |
| 301 | text_editor->begin_complex_operation(); |
| 302 | text_editor->remove_secondary_carets(); |
| 303 | text_editor->disconnect(SceneStringName(text_changed), callable_mp(this, &FindReplaceBar::_editor_text_changed)); |
| 304 | // Line as x so it gets priority in comparison, column as y. |
| 305 | Point2i orig_cursor(text_editor->get_caret_line(0), text_editor->get_caret_column(0)); |
| 306 | Point2i prev_match = Point2(-1, -1); |
| 307 | |
| 308 | bool selection_enabled = text_editor->has_selection(0); |
| 309 | if (!is_selection_only()) { |
| 310 | text_editor->deselect(); |
| 311 | selection_enabled = false; |
| 312 | } else { |
| 313 | result_line = -1; |
| 314 | result_col = -1; |
| 315 | } |
| 316 | |
| 317 | Point2i selection_begin, selection_end; |
| 318 | if (selection_enabled) { |
| 319 | selection_begin = Point2i(text_editor->get_selection_from_line(0), text_editor->get_selection_from_column(0)); |
| 320 | selection_end = Point2i(text_editor->get_selection_to_line(0), text_editor->get_selection_to_column(0)); |
| 321 | } |
| 322 | |
| 323 | int vsval = text_editor->get_v_scroll(); |
| 324 | |
| 325 | String repl_text = get_replace_text(); |
| 326 | int search_text_len = get_search_text().length(); |
| 327 | |
| 328 | int rc = 0; |
| 329 | |
| 330 | replace_all_mode = true; |
| 331 | |
| 332 | if (selection_enabled && is_selection_only()) { |
| 333 | text_editor->set_caret_line(selection_begin.width, false, true, -1, 0); |
| 334 | text_editor->set_caret_column(selection_begin.height, true, 0); |
| 335 | } else { |
| 336 | text_editor->set_caret_line(0, false, true, -1, 0); |
| 337 | text_editor->set_caret_column(0, true, 0); |
| 338 | } |
| 339 | |
| 340 | if (search_current()) { |
| 341 | do { |
| 342 | // Replace area. |
| 343 | Point2i match_from(result_line, result_col); |
| 344 | Point2i match_to(result_line, result_col + search_text_len); |
| 345 | |
| 346 | if (match_from < prev_match) { |
| 347 | break; // Done. |
| 348 | } |
| 349 | |
| 350 | prev_match = Point2i(result_line, result_col + repl_text.length()); |
| 351 | |
| 352 | text_editor->unfold_line(result_line); |
| 353 | text_editor->select(result_line, result_col, result_line, match_to.y, 0); |
| 354 | |
| 355 | if (selection_enabled) { |
| 356 | if (match_from < selection_begin || match_to > selection_end) { |
| 357 | break; // Done. |
nothing calls this directly
no test coverage detected