diff options
Diffstat (limited to 'editor/code_editor.cpp')
-rw-r--r-- | editor/code_editor.cpp | 59 |
1 files changed, 42 insertions, 17 deletions
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index be42eab636..807a45eb32 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -539,7 +539,7 @@ void FindReplaceBar::_search_text_changed(const String &p_text) { search_current(); } -void FindReplaceBar::_search_text_entered(const String &p_text) { +void FindReplaceBar::_search_text_submitted(const String &p_text) { if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { search_prev(); } else { @@ -547,7 +547,7 @@ void FindReplaceBar::_search_text_entered(const String &p_text) { } } -void FindReplaceBar::_replace_text_entered(const String &p_text) { +void FindReplaceBar::_replace_text_submitted(const String &p_text) { if (selection_only->is_pressed() && text_editor->is_selection_active()) { _replace_all(); _hide_bar(); @@ -583,15 +583,29 @@ void FindReplaceBar::set_error(const String &p_label) { emit_signal("error", p_label); } -void FindReplaceBar::set_text_edit(CodeEdit *p_text_edit) { +void FindReplaceBar::set_text_edit(CodeTextEditor *p_text_editor) { + if (p_text_editor == base_text_editor) { + return; + } + + if (base_text_editor) { + base_text_editor->remove_find_replace_bar(); + base_text_editor = nullptr; + text_editor->disconnect("text_changed", callable_mp(this, &FindReplaceBar::_editor_text_changed)); + text_editor = nullptr; + } + results_count = -1; - text_editor = p_text_edit; + base_text_editor = p_text_editor; + text_editor = base_text_editor->get_text_editor(); text_editor->connect("text_changed", callable_mp(this, &FindReplaceBar::_editor_text_changed)); + + _update_results_count(); + _update_matches_label(); } void FindReplaceBar::_bind_methods() { ClassDB::bind_method("_unhandled_input", &FindReplaceBar::_unhandled_input); - ClassDB::bind_method("_search_current", &FindReplaceBar::search_current); ADD_SIGNAL(MethodInfo("search")); @@ -629,7 +643,7 @@ FindReplaceBar::FindReplaceBar() { vbc_lineedit->add_child(search_text); search_text->set_custom_minimum_size(Size2(100 * EDSCALE, 0)); search_text->connect("text_changed", callable_mp(this, &FindReplaceBar::_search_text_changed)); - search_text->connect("text_entered", callable_mp(this, &FindReplaceBar::_search_text_entered)); + search_text->connect("text_submitted", callable_mp(this, &FindReplaceBar::_search_text_submitted)); matches_label = memnew(Label); hbc_button_search->add_child(matches_label); @@ -663,7 +677,7 @@ FindReplaceBar::FindReplaceBar() { replace_text = memnew(LineEdit); vbc_lineedit->add_child(replace_text); replace_text->set_custom_minimum_size(Size2(100 * EDSCALE, 0)); - replace_text->connect("text_entered", callable_mp(this, &FindReplaceBar::_replace_text_entered)); + replace_text->connect("text_submitted", callable_mp(this, &FindReplaceBar::_replace_text_submitted)); replace = memnew(Button); hbc_button_replace->add_child(replace); @@ -926,7 +940,7 @@ void CodeTextEditor::update_editor_settings() { text_editor->set_draw_line_numbers(EditorSettings::get_singleton()->get("text_editor/appearance/show_line_numbers")); text_editor->set_line_numbers_zero_padded(EditorSettings::get_singleton()->get("text_editor/appearance/line_numbers_zero_padded")); text_editor->set_draw_bookmarks_gutter(EditorSettings::get_singleton()->get("text_editor/appearance/show_bookmark_gutter")); - text_editor->set_hiding_enabled(EditorSettings::get_singleton()->get("text_editor/appearance/code_folding")); + text_editor->set_line_folding_enabled(EditorSettings::get_singleton()->get("text_editor/appearance/code_folding")); text_editor->set_draw_fold_gutter(EditorSettings::get_singleton()->get("text_editor/appearance/code_folding")); text_editor->set_wrap_enabled(EditorSettings::get_singleton()->get("text_editor/appearance/word_wrap")); text_editor->set_show_line_length_guidelines(EditorSettings::get_singleton()->get("text_editor/appearance/show_line_length_guidelines")); @@ -939,6 +953,25 @@ void CodeTextEditor::update_editor_settings() { text_editor->set_auto_brace_completion(EditorSettings::get_singleton()->get("text_editor/completion/auto_brace_complete")); } +void CodeTextEditor::set_find_replace_bar(FindReplaceBar *p_bar) { + if (find_replace_bar) { + return; + } + + find_replace_bar = p_bar; + find_replace_bar->set_text_edit(this); + find_replace_bar->connect("error", callable_mp(error, &Label::set_text)); +} + +void CodeTextEditor::remove_find_replace_bar() { + if (!find_replace_bar) { + return; + } + + find_replace_bar->disconnect("error", callable_mp(error, &Label::set_text)); + find_replace_bar = nullptr; +} + void CodeTextEditor::trim_trailing_whitespace() { bool trimed_whitespace = false; for (int i = 0; i < text_editor->get_line_count(); i++) { @@ -1469,6 +1502,7 @@ void CodeTextEditor::set_error_pos(int p_line, int p_column) { void CodeTextEditor::goto_error() { if (error->get_text() != "") { + text_editor->unfold_line(error_line); text_editor->cursor_set_line(error_line); text_editor->cursor_set_column(error_column); text_editor->center_viewport_to_cursor(); @@ -1760,14 +1794,6 @@ CodeTextEditor::CodeTextEditor() { } break; } - // Added second so it opens at the bottom, so it won't shift the entire text editor when opening. - find_replace_bar = memnew(FindReplaceBar); - add_child(find_replace_bar); - find_replace_bar->set_h_size_flags(SIZE_EXPAND_FILL); - find_replace_bar->hide(); - - find_replace_bar->set_text_edit(text_editor); - text_editor->set_draw_line_numbers(true); text_editor->set_brace_matching(true); text_editor->set_auto_indent(true); @@ -1808,7 +1834,6 @@ CodeTextEditor::CodeTextEditor() { error->set_v_size_flags(SIZE_EXPAND | SIZE_SHRINK_CENTER); error->set_mouse_filter(MOUSE_FILTER_STOP); error->connect("gui_input", callable_mp(this, &CodeTextEditor::_error_pressed)); - find_replace_bar->connect("error", callable_mp(error, &Label::set_text)); // Warnings warning_button = memnew(Button); |