diff options
author | Michael Alexsander Silva Dias <michaelalexsander@protonmail.com> | 2019-08-07 23:06:33 -0300 |
---|---|---|
committer | Michael Alexsander Silva Dias <michaelalexsander@protonmail.com> | 2019-08-07 23:06:33 -0300 |
commit | 699afca7ef6556c1c30539291a7c8af0c3fcc4d6 (patch) | |
tree | 1cdedeec81eddd7b95c32dba34df911ec4bec366 /editor/plugins | |
parent | 05be97a607105dbd8fb93bc90d5fc3dd3eaf94a2 (diff) |
Fix error when going to a text file by clicking in a result from "Find in files"
Diffstat (limited to 'editor/plugins')
-rw-r--r-- | editor/plugins/script_editor_plugin.cpp | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 02d4b9d1d7..16cc9978ee 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -2989,33 +2989,38 @@ void ScriptEditor::_on_find_in_files_requested(String text) { void ScriptEditor::_on_find_in_files_result_selected(String fpath, int line_number, int begin, int end) { - RES res = ResourceLoader::load(fpath); - if (fpath.get_extension() == "shader") { - ShaderEditorPlugin *shader_editor = Object::cast_to<ShaderEditorPlugin>(EditorNode::get_singleton()->get_editor_data().get_editor("Shader")); - shader_editor->edit(res.ptr()); - shader_editor->make_visible(true); - shader_editor->get_shader_editor()->goto_line_selection(line_number - 1, begin, end); - } else { - Ref<Script> script = res; - if (script.is_valid()) { - edit(script); + if (ResourceLoader::exists(fpath)) { + RES res = ResourceLoader::load(fpath); + + if (fpath.get_extension() == "shader") { + ShaderEditorPlugin *shader_editor = Object::cast_to<ShaderEditorPlugin>(EditorNode::get_singleton()->get_editor_data().get_editor("Shader")); + shader_editor->edit(res.ptr()); + shader_editor->make_visible(true); + shader_editor->get_shader_editor()->goto_line_selection(line_number - 1, begin, end); + return; + } else { + Ref<Script> script = res; + if (script.is_valid()) { + edit(script); - ScriptTextEditor *ste = Object::cast_to<ScriptTextEditor>(_get_current_editor()); - if (ste) { - ste->goto_line_selection(line_number - 1, begin, end); + ScriptTextEditor *ste = Object::cast_to<ScriptTextEditor>(_get_current_editor()); + if (ste) { + ste->goto_line_selection(line_number - 1, begin, end); + } + return; } - } else { //if file is not valid script, load as text file + } + } - Error err; - Ref<TextFile> text_file = _load_text_file(fpath, &err); - if (text_file.is_valid()) { - edit(text_file); + // If the file is not a valid resource/script, load it as a text file. + Error err; + Ref<TextFile> text_file = _load_text_file(fpath, &err); + if (text_file.is_valid()) { + edit(text_file); - TextEditor *te = Object::cast_to<TextEditor>(_get_current_editor()); - if (te) { - te->goto_line_selection(line_number - 1, begin, end); - } - } + TextEditor *te = Object::cast_to<TextEditor>(_get_current_editor()); + if (te) { + te->goto_line_selection(line_number - 1, begin, end); } } } |