summaryrefslogtreecommitdiffstats
path: root/editor/plugins/script_text_editor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/plugins/script_text_editor.cpp')
-rw-r--r--editor/plugins/script_text_editor.cpp71
1 files changed, 52 insertions, 19 deletions
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index bed7739239..ee8767e6a6 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -664,7 +664,7 @@ static Node *_find_node_for_script(Node *p_base, Node *p_current, const Ref<Scri
return nullptr;
}
-static void _find_changed_scripts_for_external_editor(Node *p_base, Node *p_current, Set<Ref<Script>> &r_scripts) {
+static void _find_changed_scripts_for_external_editor(Node *p_base, Node *p_current, RBSet<Ref<Script>> &r_scripts) {
if (p_current->get_owner() != p_base && p_base != p_current) {
return;
}
@@ -686,14 +686,14 @@ void ScriptEditor::_update_modified_scripts_for_external_editor(Ref<Script> p_fo
ERR_FAIL_COND(!get_tree());
- Set<Ref<Script>> scripts;
+ RBSet<Ref<Script>> scripts;
Node *base = get_tree()->get_edited_scene_root();
if (base) {
_find_changed_scripts_for_external_editor(base, base, scripts);
}
- for (Set<Ref<Script>>::Element *E = scripts.front(); E; E = E->next()) {
+ for (RBSet<Ref<Script>>::Element *E = scripts.front(); E; E = E->next()) {
Ref<Script> script = E->get();
if (p_for_script.is_valid() && p_for_script != script) {
@@ -970,7 +970,7 @@ void ScriptTextEditor::_update_connected_methods() {
}
Vector<Node *> nodes = _find_all_node_for_script(base, base, script);
- Set<StringName> methods_found;
+ RBSet<StringName> methods_found;
for (int i = 0; i < nodes.size(); i++) {
List<Connection> connections;
nodes[i]->get_signals_connected_to_this(&connections);
@@ -1371,11 +1371,11 @@ void ScriptTextEditor::add_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_hig
void ScriptTextEditor::set_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) {
ERR_FAIL_COND(p_highlighter.is_null());
- Map<String, Ref<EditorSyntaxHighlighter>>::Element *el = highlighters.front();
- while (el != nullptr) {
- int highlighter_index = highlighter_menu->get_item_idx_from_text(el->key());
- highlighter_menu->set_item_checked(highlighter_index, el->value() == p_highlighter);
- el = el->next();
+ HashMap<String, Ref<EditorSyntaxHighlighter>>::Iterator el = highlighters.begin();
+ while (el) {
+ int highlighter_index = highlighter_menu->get_item_idx_from_text(el->key);
+ highlighter_menu->set_item_checked(highlighter_index, el->value == p_highlighter);
+ ++el;
}
CodeEdit *te = code_editor->get_text_editor();
@@ -1558,19 +1558,52 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
Array nodes = d["nodes"];
String text_to_drop;
- for (int i = 0; i < nodes.size(); i++) {
- if (i > 0) {
- text_to_drop += ",";
- }
- NodePath np = nodes[i];
- Node *node = get_node(np);
- if (!node) {
- continue;
+ if (Input::get_singleton()->is_key_pressed(Key::CTRL)) {
+ bool use_type = EDITOR_GET("text_editor/completion/add_type_hints");
+ for (int i = 0; i < nodes.size(); i++) {
+ NodePath np = nodes[i];
+ Node *node = get_node(np);
+ if (!node) {
+ continue;
+ }
+
+ String 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;
+ }
+ }
+
+ 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);
+ } else {
+ text_to_drop += vformat("@onready var %s = $%s\n", variable_name, path);
+ }
}
+ } else {
+ for (int i = 0; i < nodes.size(); i++) {
+ if (i > 0) {
+ text_to_drop += ", ";
+ }
+
+ NodePath np = nodes[i];
+ Node *node = get_node(np);
+ if (!node) {
+ continue;
+ }
- String path = sn->get_path_to(node);
- text_to_drop += path.c_escape().quote(quote_style);
+ String 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;
+ }
}
te->set_caret_line(row);