Find files for EditorInterface.get_script_editor().get_open_script_editors()

Godot Version

4.6.3

Question

In Godot 4.3, given a file path, the following code allowed me to find if it was open in the script editor and read its content:

var script_editor := EditorInterface.get_script_editor()
var open_script_editors := script_editor.get_open_script_editors()
for editor in open_script_editors:
	if editor.has_meta(&"_edit_res_path"):
		var editor_path = editor.get_meta(&"_edit_res_path")
		if editor_path == _file_path:
			var content = editor.get_base_editor().text.split("\n")

It seems from 4.4+, meta “_edit_res_path” was removed.

I know EditorInterface.get_script_editor().get_open_scripts() could give me the actual Script objects and I could read the paths from them, however the editor can also open text files, and those are not included in get_open_scripts().

My question: For a given item of get_open_script_editors(), is there any way to know what file it is editing?

What I’m trying to do

Given a file path, I want to check if it the file is open (even if not focused in the current code editor), if so, I want to read it from the editor itself, so I can read the latest changes the user has made, even if not saved.

Unfortunately, without meta “_edit_res_path” all the editors I’m getting from get_open_script_editors() seem to be objects with no context about the file they are editing.

As far as I can tell the edited resource is internal and not exposed to scripting. You could open an issue in the issue tracker to expose it to scripting.

As a workaround the path of opened files is saved in .godot/editor/editor_layout.cfg so you can get them like:

@tool
extends EditorScript


func _run() -> void:
	var config = ConfigFile.new()
	config.load("res://.godot/editor/editor_layout.cfg")
	print(config.get_value("ScriptEditor", "open_scripts"))