@@ -2554,63 +2554,11 @@ bool ScriptEditor::edit(const Ref<Resource> &p_resource, int p_line, int p_col,
25542554 if (use_external_editor &&
25552555 (EditorDebuggerNode::get_singleton ()->get_dump_stack_script () != p_resource || EditorDebuggerNode::get_singleton ()->get_debug_with_external_editor ()) &&
25562556 p_resource->get_path ().is_resource_file ()) {
2557- String path = EDITOR_GET (" text_editor/external/exec_path" );
2558- String flags = EDITOR_GET (" text_editor/external/exec_flags" );
2559-
2560- List<String> args;
2561- bool has_file_flag = false ;
2562- String script_path = ProjectSettings::get_singleton ()->globalize_path (p_resource->get_path ());
2563-
2564- if (flags.size ()) {
2565- String project_path = ProjectSettings::get_singleton ()->get_resource_path ();
2566-
2567- flags = flags.replacen (" {line}" , itos (MAX (p_line + 1 , 1 )));
2568- flags = flags.replacen (" {col}" , itos (p_col + 1 ));
2569- flags = flags.strip_edges ().replace (" \\\\ " , " \\ " );
2570-
2571- int from = 0 ;
2572- int num_chars = 0 ;
2573- bool inside_quotes = false ;
2574-
2575- for (int i = 0 ; i < flags.size (); i++) {
2576- if (flags[i] == ' "' && (!i || flags[i - 1 ] != ' \\ ' )) {
2577- if (!inside_quotes) {
2578- from++;
2579- }
2580- inside_quotes = !inside_quotes;
2581-
2582- } else if (flags[i] == ' \0 ' || (!inside_quotes && flags[i] == ' ' )) {
2583- String arg = flags.substr (from, num_chars);
2584- if (arg.contains (" {file}" )) {
2585- has_file_flag = true ;
2586- }
2587-
2588- // do path replacement here, else there will be issues with spaces and quotes
2589- arg = arg.replacen (" {project}" , project_path);
2590- arg = arg.replacen (" {file}" , script_path);
2591- args.push_back (arg);
2592-
2593- from = i + 1 ;
2594- num_chars = 0 ;
2595- } else {
2596- num_chars++;
2597- }
2598- }
2599- }
2600-
2601- // Default to passing script path if no {file} flag is specified.
2602- if (!has_file_flag) {
2603- args.push_back (script_path);
2604- }
2605-
2606- if (!path.is_empty ()) {
2607- Error err = OS::get_singleton ()->create_process (path, args);
2608- if (err == OK) {
2609- return false ;
2610- }
2557+ if (ScriptEditorPlugin::open_in_external_editor (ProjectSettings::get_singleton ()->globalize_path (p_resource->get_path ()), p_line, p_col)) {
2558+ return false ;
2559+ } else {
2560+ ERR_PRINT (" Couldn't open external text editor, falling back to the internal editor. Review your `text_editor/external/` editor settings." );
26112561 }
2612-
2613- ERR_PRINT (" Couldn't open external text editor, falling back to the internal editor. Review your `text_editor/external/` editor settings." );
26142562 }
26152563
26162564 for (int i = 0 ; i < tab_container->get_tab_count (); i++) {
@@ -4629,6 +4577,63 @@ void ScriptEditorPlugin::_notification(int p_what) {
46294577 }
46304578}
46314579
4580+ bool ScriptEditorPlugin::open_in_external_editor (const String &p_path, int p_line, int p_col, bool p_ignore_project) {
4581+ const String path = EDITOR_GET (" text_editor/external/exec_path" );
4582+ if (path.is_empty ()) {
4583+ return false ;
4584+ }
4585+
4586+ String flags = EDITOR_GET (" text_editor/external/exec_flags" );
4587+
4588+ List<String> args;
4589+ bool has_file_flag = false ;
4590+
4591+ if (!flags.is_empty ()) {
4592+ flags = flags.replacen (" {line}" , itos (MAX (p_line + 1 , 1 )));
4593+ flags = flags.replacen (" {col}" , itos (p_col + 1 ));
4594+ flags = flags.strip_edges ().replace (" \\\\ " , " \\ " );
4595+
4596+ int from = 0 ;
4597+ int num_chars = 0 ;
4598+ bool inside_quotes = false ;
4599+
4600+ for (int i = 0 ; i < flags.size (); i++) {
4601+ if (flags[i] == ' "' && (!i || flags[i - 1 ] != ' \\ ' )) {
4602+ if (!inside_quotes) {
4603+ from++;
4604+ }
4605+ inside_quotes = !inside_quotes;
4606+
4607+ } else if (flags[i] == ' \0 ' || (!inside_quotes && flags[i] == ' ' )) {
4608+ String arg = flags.substr (from, num_chars);
4609+ if (arg.contains (" {file}" )) {
4610+ has_file_flag = true ;
4611+ }
4612+
4613+ // Do path replacement here, else there will be issues with spaces and quotes
4614+ if (p_ignore_project) {
4615+ arg = arg.replacen (" {project}" , String ());
4616+ } else {
4617+ arg = arg.replacen (" {project}" , ProjectSettings::get_singleton ()->get_resource_path ());
4618+ }
4619+ arg = arg.replacen (" {file}" , p_path);
4620+ args.push_back (arg);
4621+
4622+ from = i + 1 ;
4623+ num_chars = 0 ;
4624+ } else {
4625+ num_chars++;
4626+ }
4627+ }
4628+ }
4629+
4630+ // Default to passing script path if no {file} flag is specified.
4631+ if (!has_file_flag) {
4632+ args.push_back (p_path);
4633+ }
4634+ return OS::get_singleton ()->create_process (path, args) == OK;
4635+ }
4636+
46324637void ScriptEditorPlugin::edit (Object *p_object) {
46334638 if (Object::cast_to<Script>(p_object)) {
46344639 Script *p_script = Object::cast_to<Script>(p_object);
0 commit comments