From 5c498f714dafc3bcbb7601c5665b518513b353cb Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Mon, 26 Dec 2022 14:34:37 +0800 Subject: Fix error when dropping script into script editor --- editor/plugins/script_editor_plugin.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index bb5491fcb5..45a48093e9 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -2954,15 +2954,18 @@ void ScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Co Ref res = open_file(file); if (res.is_valid()) { - if (tab_container->get_tab_count() > num_tabs_before) { + const int num_tabs = tab_container->get_tab_count(); + if (num_tabs > num_tabs_before) { tab_container->move_child(tab_container->get_tab_control(tab_container->get_tab_count() - 1), new_index); - num_tabs_before = tab_container->get_tab_count(); - } else { /* Maybe script was already open */ + num_tabs_before = num_tabs; + } else if (num_tabs > 0) { /* Maybe script was already open */ tab_container->move_child(tab_container->get_tab_control(tab_container->get_current_tab()), new_index); } } } - tab_container->set_current_tab(new_index); + if (tab_container->get_tab_count() > 0) { + tab_container->set_current_tab(new_index); + } _update_script_names(); } } -- cgit v1.2.3