diff --git a/core/script_language.h b/core/script_language.h index 22f83080bc3..6f65892afe8 100644 --- a/core/script_language.h +++ b/core/script_language.h @@ -219,6 +219,7 @@ struct ScriptCodeCompletionOption { String display; String insert_text; RES icon; + Variant default_value; ScriptCodeCompletionOption() { kind = KIND_PLAIN_TEXT; diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index bef8f6c5d67..9008955191a 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -1881,6 +1881,12 @@ static void _find_identifiers_in_class(const GDScriptCompletionContext &p_contex if (!p_only_functions) { for (Map::Element *E = p_context._class->constant_expressions.front(); E; E = E->next()) { ScriptCodeCompletionOption option(E->key(), ScriptCodeCompletionOption::KIND_CONSTANT); + if (E->get().expression && E->get().expression->type == GDScriptParser::Node::TYPE_CONSTANT) { + GDScriptParser::ConstantNode *cnode = (GDScriptParser::ConstantNode *)E->get().expression; + if (cnode) { + option.default_value = cnode->value; + } + } r_result.insert(option.display, option); } for (int i = 0; i < p_context._class->subclasses.size(); i++) { @@ -2572,6 +2578,11 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path Variant::get_constants_for_type(parser.get_completion_built_in_constant(), &constants); for (List::Element *E = constants.front(); E; E = E->next()) { ScriptCodeCompletionOption option(E->get().operator String(), ScriptCodeCompletionOption::KIND_CONSTANT); + bool valid = false; + Variant default_value = Variant::get_constant_value(parser.get_completion_built_in_constant(), E->get(), &valid); + if (valid) { + option.default_value = default_value; + } options.insert(option.display, option); } } break; diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index a2de4004229..43d0b87e9d1 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1581,6 +1581,17 @@ void TextEdit::_notification(int p_what) { Size2 icon_area_size(get_row_height(), get_row_height()); w += icon_area_size.width + icon_hsep; + int line_from = CLAMP(completion_index - lines / 2, 0, completion_options_size - lines); + + for (int i = 0; i < lines; i++) { + int l = line_from + i; + ERR_CONTINUE(l < 0 || l >= completion_options_size); + if (completion_options[l].default_value.get_type() == Variant::COLOR) { + w += icon_area_size.width; + break; + } + } + int th = h + csb->get_minimum_size().y; if (cursor_pos.y + get_row_height() + th > get_size().height) { @@ -1606,7 +1617,6 @@ void TextEdit::_notification(int p_what) { if (cache.completion_background_color.a > 0.01) { VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(completion_rect.position, completion_rect.size + Size2(scrollw, 0)), cache.completion_background_color); } - int line_from = CLAMP(completion_index - lines / 2, 0, completion_options_size - lines); VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(completion_rect.position.x, completion_rect.position.y + (completion_index - line_from) * get_row_height()), Size2(completion_rect.size.width, get_row_height())), cache.completion_selected_color); draw_rect(Rect2(completion_rect.position + Vector2(icon_area_size.x + icon_hsep, 0), Size2(MIN(nofs, completion_rect.size.width - (icon_area_size.x + icon_hsep)), completion_rect.size.height)), cache.completion_existing_color); @@ -1635,6 +1645,11 @@ void TextEdit::_notification(int p_what) { } title_pos.x = icon_area.position.x + icon_area.size.width + icon_hsep; + + if (completion_options[l].default_value.get_type() == Variant::COLOR) { + draw_rect(Rect2(Point2(completion_rect.position.x + completion_rect.size.width - icon_area_size.x, icon_area.position.y), icon_area_size), (Color)completion_options[l].default_value); + } + draw_string(cache.font, title_pos, completion_options[l].display, text_color, completion_rect.size.width - (icon_area_size.x + icon_hsep)); }