1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-10 13:00:37 +00:00

Merge pull request #49650 from KoBeWi/FindReplaceCrash

Fix crash with FindReplaceBar
This commit is contained in:
Rémi Verschelde
2021-06-24 19:21:01 +02:00
committed by GitHub
3 changed files with 28 additions and 3 deletions

View File

@@ -105,6 +105,11 @@ void FindReplaceBar::_notification(int p_what) {
hide_button->set_custom_minimum_size(hide_button->get_normal_texture()->get_size()); hide_button->set_custom_minimum_size(hide_button->get_normal_texture()->get_size());
} else if (p_what == NOTIFICATION_THEME_CHANGED) { } else if (p_what == NOTIFICATION_THEME_CHANGED) {
matches_label->add_theme_color_override("font_color", results_count > 0 ? get_theme_color("font_color", "Label") : get_theme_color("error_color", "Editor")); matches_label->add_theme_color_override("font_color", results_count > 0 ? get_theme_color("font_color", "Label") : get_theme_color("error_color", "Editor"));
} else if (p_what == NOTIFICATION_PREDELETE) {
if (base_text_editor) {
base_text_editor->remove_find_replace_bar();
base_text_editor = nullptr;
}
} }
} }
@@ -595,6 +600,10 @@ void FindReplaceBar::set_text_edit(CodeTextEditor *p_text_editor) {
text_editor = nullptr; text_editor = nullptr;
} }
if (!p_text_editor) {
return;
}
results_count = -1; results_count = -1;
base_text_editor = p_text_editor; base_text_editor = p_text_editor;
text_editor = base_text_editor->get_text_editor(); text_editor = base_text_editor->get_text_editor();
@@ -1667,6 +1676,11 @@ void CodeTextEditor::_notification(int p_what) {
} }
set_process_input(is_visible_in_tree()); set_process_input(is_visible_in_tree());
} break; } break;
case NOTIFICATION_PREDELETE: {
if (find_replace_bar) {
find_replace_bar->set_text_edit(nullptr);
}
} break;
default: default:
break; break;
} }

View File

@@ -760,6 +760,7 @@ void ScriptEditor::_close_tab(int p_idx, bool p_save, bool p_history_back) {
_update_members_overview_visibility(); _update_members_overview_visibility();
_update_help_overview_visibility(); _update_help_overview_visibility();
_save_layout(); _save_layout();
_update_find_replace_bar();
} }
void ScriptEditor::_close_current_tab(bool p_save) { void ScriptEditor::_close_current_tab(bool p_save) {
@@ -829,6 +830,7 @@ void ScriptEditor::_close_all_tabs() {
_close_current_tab(false); _close_current_tab(false);
} }
_update_find_replace_bar();
} }
void ScriptEditor::_ask_close_current_unsaved_tab(ScriptEditorBase *current) { void ScriptEditor::_ask_close_current_unsaved_tab(ScriptEditorBase *current) {
@@ -1640,15 +1642,13 @@ void ScriptEditor::ensure_select_current() {
ScriptEditorBase *se = _get_current_editor(); ScriptEditorBase *se = _get_current_editor();
if (se) { if (se) {
se->enable_editor(); se->enable_editor();
se->set_find_replace_bar(find_replace_bar);
if (!grab_focus_block && is_visible_in_tree()) { if (!grab_focus_block && is_visible_in_tree()) {
se->ensure_focus(); se->ensure_focus();
} }
} else {
find_replace_bar->hide();
} }
} }
_update_find_replace_bar();
_update_selected_editor_menu(); _update_selected_editor_menu();
} }
@@ -2520,6 +2520,16 @@ void ScriptEditor::_file_removed(const String &p_removed_file) {
} }
} }
void ScriptEditor::_update_find_replace_bar() {
ScriptEditorBase *se = _get_current_editor();
if (se) {
se->set_find_replace_bar(find_replace_bar);
} else {
find_replace_bar->set_text_edit(nullptr);
find_replace_bar->hide();
}
}
void ScriptEditor::_autosave_scripts() { void ScriptEditor::_autosave_scripts() {
save_all_scripts(); save_all_scripts();
} }

View File

@@ -328,6 +328,7 @@ class ScriptEditor : public PanelContainer {
void _show_error_dialog(String p_path); void _show_error_dialog(String p_path);
void _close_tab(int p_idx, bool p_save = true, bool p_history_back = true); void _close_tab(int p_idx, bool p_save = true, bool p_history_back = true);
void _update_find_replace_bar();
void _close_current_tab(bool p_save = true); void _close_current_tab(bool p_save = true);
void _close_discard_current_tab(const String &p_str); void _close_discard_current_tab(const String &p_str);