diff options
author | stmSi <stm1998sithumyo@gmail.com> | 2023-03-07 02:49:14 +0630 |
---|---|---|
committer | Yuri Sizov <yuris@humnom.net> | 2023-03-27 17:06:43 +0200 |
commit | 0dab32f317c4520ae2463f33d61381214a9c87c5 (patch) | |
tree | 2a4e6495da8be0ee557868f127db93da3647a863 /editor/plugins/script_editor_plugin.cpp | |
parent | 865a0b45072e5749b6082e895d94c2ee94a6e3ea (diff) |
Fix `Find in Files` Search Results cannot open builtin script
(cherry picked from commit f1f4c5b10b934402acdfa279782a93cbe4403740)
Diffstat (limited to 'editor/plugins/script_editor_plugin.cpp')
-rw-r--r-- | editor/plugins/script_editor_plugin.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index a584d357cd..49c815526b 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -3586,7 +3586,72 @@ void ScriptEditor::_on_find_in_files_result_selected(String fpath, int line_numb shader_editor->get_shader_editor(res)->goto_line_selection(line_number - 1, begin, end); return; } else if (fpath.get_extension() == "tscn") { + Ref<FileAccess> f = FileAccess::open(fpath, FileAccess::READ); + bool is_script_found = false; + + // Starting from top of the tscn file. + int scr_start_line = 1; + + String scr_header = "[sub_resource type=\"GDScript\" id=\""; + String scr_id = ""; + String line = ""; + + int l = 0; + + while (!f->eof_reached()) { + line = f->get_line(); + l++; + + if (!line.begins_with(scr_header)) { + continue; + } + + // Found the end of the script. + scr_id = line.get_slice(scr_header, 1); + scr_id = scr_id.get_slice("\"", 0); + + scr_start_line = l + 1; + int scr_line_count = 0; + + do { + line = f->get_line(); + l++; + String strline = line.strip_edges(); + + if (strline.ends_with("\"") && !strline.ends_with("\\\"")) { + // Found the end of script. + break; + } + scr_line_count++; + + } while (!f->eof_reached()); + + if (line_number > scr_start_line + scr_line_count) { + // Find in another built-in GDScript. + continue; + } + + // Real line number of the built-in script. + line_number = line_number - scr_start_line; + + is_script_found = true; + break; + } + EditorNode::get_singleton()->load_scene(fpath); + + if (is_script_found && !scr_id.is_empty()) { + Ref<Script> scr = ResourceLoader::load(fpath + "::" + scr_id, "Script"); + if (scr.is_valid()) { + edit(scr); + ScriptTextEditor *ste = Object::cast_to<ScriptTextEditor>(_get_current_editor()); + + if (ste) { + ste->goto_line_selection(line_number, begin, end); + } + } + } + return; } else { Ref<Script> scr = res; |