summaryrefslogtreecommitdiffstats
path: root/editor/plugins/script_text_editor.cpp
diff options
context:
space:
mode:
authorGeorge Marques <george@gmarqu.es>2022-05-26 12:56:39 -0300
committerGeorge Marques <george@gmarqu.es>2022-05-27 13:46:18 -0300
commiteba3e0a9fce1f10e8ad7311e84e9f3d38dae008e (patch)
treeef292d28ba674b16bcbf7d51b9a45a566eb27516 /editor/plugins/script_text_editor.cpp
parentd81c5eab8cfd1d91ef2cf1599a6b929ccbed0a3a (diff)
downloadredot-engine-eba3e0a9fce1f10e8ad7311e84e9f3d38dae008e.tar.gz
GDScript: Support `%` in shorthand for `get_node`
The `%` is used in scene unique nodes. Now `%` can also be used instead of `$` for the shorthand, besides being allowed generally anywhere in the path as the prefix for a node name.
Diffstat (limited to 'editor/plugins/script_text_editor.cpp')
-rw-r--r--editor/plugins/script_text_editor.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index a4bccf30e3..f93ea651fd 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -1568,9 +1568,11 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
continue;
}
+ bool is_unique = false;
String path;
if (node->is_unique_name_in_owner()) {
- path = "%" + node->get_name();
+ path = node->get_name();
+ is_unique = true;
} else {
path = sn->get_path_to(node);
}
@@ -1583,9 +1585,9 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
String variable_name = String(node->get_name()).camelcase_to_underscore(true).validate_identifier();
if (use_type) {
- text_to_drop += vformat("@onready var %s: %s = $%s\n", variable_name, node->get_class_name(), path);
+ text_to_drop += vformat("@onready var %s: %s = %s%s\n", variable_name, node->get_class_name(), is_unique ? "%" : "$", path);
} else {
- text_to_drop += vformat("@onready var %s = $%s\n", variable_name, path);
+ text_to_drop += vformat("@onready var %s = %s%s\n", variable_name, is_unique ? "%" : "$", path);
}
}
} else {
@@ -1600,19 +1602,22 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
continue;
}
+ bool is_unique = false;
String path;
if (node->is_unique_name_in_owner()) {
- path = "%" + node->get_name();
+ path = node->get_name();
+ is_unique = true;
} else {
path = sn->get_path_to(node);
}
+
for (const String &segment : path.split("/")) {
if (!segment.is_valid_identifier()) {
path = path.c_escape().quote(quote_style);
break;
}
}
- text_to_drop += "$" + path;
+ text_to_drop += (is_unique ? "%" : "$") + path;
}
}