From 8628738a345b1f42ea1033c1669d38fb274482dd Mon Sep 17 00:00:00 2001
From: nikitalita <69168929+nikitalita@users.noreply.github.com>
Date: Wed, 18 Mar 2026 09:49:30 -0700
Subject: [PATCH] Add ScriptEditor::close_file()
---
doc/classes/ScriptEditor.xml | 8 ++++++++
editor/script/script_editor_plugin.cpp | 15 +++++++++++++++
editor/script/script_editor_plugin.h | 2 ++
3 files changed, 25 insertions(+)
diff --git a/doc/classes/ScriptEditor.xml b/doc/classes/ScriptEditor.xml
index d0f602826f..733ba9acf3 100644
--- a/doc/classes/ScriptEditor.xml
+++ b/doc/classes/ScriptEditor.xml
@@ -18,6 +18,14 @@
[b]Note:[/b] This should be called whenever the script is changed to keep the open documentation state up to date.
+
+
+
+
+ Closes the file at the given [param path], discarding any unsaved changes.
+ Returns [constant OK] on success or [constant ERR_FILE_NOT_FOUND] if the file is not found.
+
+
diff --git a/editor/script/script_editor_plugin.cpp b/editor/script/script_editor_plugin.cpp
index b64240c677..d390226fc8 100644
--- a/editor/script/script_editor_plugin.cpp
+++ b/editor/script/script_editor_plugin.cpp
@@ -2611,6 +2611,20 @@ Ref ScriptEditor::open_file(const String &p_file) {
return Ref();
}
+Error ScriptEditor::close_file(const String &p_file) {
+ for (int i = 0; i < tab_container->get_tab_count(); i++) {
+ ScriptEditorBase *seb = Object::cast_to(tab_container->get_tab_control(i));
+ if (seb && seb->get_edited_resource()->get_path() == p_file) {
+ if (seb->is_unsaved()) {
+ seb->get_edited_resource()->reload_from_file();
+ }
+ _close_tab(i, false, _get_current_editor() == seb);
+ return OK;
+ }
+ }
+ return ERR_FILE_NOT_FOUND;
+}
+
void ScriptEditor::_add_callback(Object *p_obj, const String &p_function, const PackedStringArray &p_args) {
ERR_FAIL_NULL(p_obj);
Ref