diff --git a/doc/classes/EditorSettings.xml b/doc/classes/EditorSettings.xml index ba61fec4230..c4aa05fcb31 100644 --- a/doc/classes/EditorSettings.xml +++ b/doc/classes/EditorSettings.xml @@ -1237,6 +1237,9 @@ The space to add between lines (in pixels). Greater line spacing can help improve readability at the cost of displaying fewer lines on screen. + + If [code]true[/code], documentation tooltips will appear when hovering over a symbol. + If [code]true[/code], tool scripts will be automatically soft-reloaded after they are saved. diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 9a5a51a18a2..93f280c1370 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -719,6 +719,9 @@ void EditorSettings::_load_defaults(Ref p_extra_config) { _initial_set("text_editor/behavior/files/auto_reload_and_parse_scripts_on_save", true); _initial_set("text_editor/behavior/files/open_dominant_script_on_scene_change", false, true); + // Behavior: Documentation + _initial_set("text_editor/behavior/documentation/enable_tooltips", true, true); + // Script list _initial_set("text_editor/script_list/show_members_overview", true, true); _initial_set("text_editor/script_list/sort_members_outline_alphabetically", false, true); diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index a6c18d3b31c..8461d837e69 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -497,6 +497,24 @@ ScriptEditor *ScriptEditor::script_editor = nullptr; /*** SCRIPT EDITOR ******/ +String ScriptEditor::_get_debug_tooltip(const String &p_text, Node *p_se) { + if (EDITOR_GET("text_editor/behavior/documentation/enable_tooltips")) { + return String(); + } + + // NOTE: See also `ScriptTextEditor::_show_symbol_tooltip()` for documentation tooltips enabled. + String debug_value = EditorDebuggerNode::get_singleton()->get_var_value(p_text); + if (!debug_value.is_empty()) { + constexpr int DISPLAY_LIMIT = 1024; + if (debug_value.size() > DISPLAY_LIMIT) { + debug_value = debug_value.left(DISPLAY_LIMIT) + "... " + TTR("(truncated)"); + } + debug_value = TTR("Current value: ") + debug_value; + } + + return debug_value; +} + void ScriptEditor::_breaked(bool p_breaked, bool p_can_debug) { if (external_editor_active) { return; @@ -2626,9 +2644,12 @@ bool ScriptEditor::edit(const Ref &p_resource, int p_line, int p_col, } // If we delete a script within the filesystem, the original resource path - // is lost, so keep it as metadata to figure out the exact tab to delete. + // is lost, so keep it as `edited_file_data` to figure out the exact tab to delete. se->edited_file_data.path = p_resource->get_path(); se->edited_file_data.last_modified_time = FileAccess::get_modified_time(p_resource->get_path()); + + se->set_tooltip_request_func(callable_mp(this, &ScriptEditor::_get_debug_tooltip)); + if (se->get_edit_menu()) { se->get_edit_menu()->hide(); menu_hb->add_child(se->get_edit_menu()); diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index 50e6cfd91cd..02e0529a7cf 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -440,6 +440,7 @@ class ScriptEditor : public PanelContainer { void _goto_script_line(Ref p_script, int p_line); void _set_execution(Ref p_script, int p_line); void _clear_execution(Ref p_script); + String _get_debug_tooltip(const String &p_text, Node *p_se); void _breaked(bool p_breaked, bool p_can_debug); void _script_created(Ref