From 12f00535555f8ac94a3da2a561f51357502e7a6d Mon Sep 17 00:00:00 2001 From: Paulb23 Date: Mon, 28 Jun 2021 17:14:44 +0100 Subject: Move auto brace completion to CodeEdit --- doc/classes/CodeEdit.xml | 45 +++++++++++++++++++++++++++++++++++++++++++++ doc/classes/TextEdit.xml | 8 ++++++++ 2 files changed, 53 insertions(+) (limited to 'doc/classes') diff --git a/doc/classes/CodeEdit.xml b/doc/classes/CodeEdit.xml index 6a3f38f51e..1a6311c905 100644 --- a/doc/classes/CodeEdit.xml +++ b/doc/classes/CodeEdit.xml @@ -30,6 +30,18 @@ Override this method to define what happens when the user requests code completion. If [code]force[/code] is true, any checks should be bypassed. + + + + + + + + + Adds a brace pair. + Both the start and end keys must be symbols. Only the start key has to be unique. + + @@ -137,6 +149,15 @@ Folds the given line, if possible (see [method can_fold_line]). + + + + + + + Gets the matching auto brace close key for [code]open_key[/code]. + + @@ -219,6 +240,24 @@ Returns the full text with char [code]0xFFFF[/code] at the caret location. + + + + + + + Returns [code]true[/code] if close key [code]close_key[/code] exists. + + + + + + + + + Returns [code]true[/code] if open key [code]open_key[/code] exists. + + @@ -378,6 +417,12 @@ + + Sets whether brace pairs should be autocompleted. + + + Sets the brace pairs to be autocompleted. + Sets whether code completion is allowed. diff --git a/doc/classes/TextEdit.xml b/doc/classes/TextEdit.xml index 5444721e10..cc5c36bbd3 100644 --- a/doc/classes/TextEdit.xml +++ b/doc/classes/TextEdit.xml @@ -16,6 +16,14 @@ A virtual method that is called whenever backspace is triggered. + + + + + + + + -- cgit v1.2.3 From d1a1ad127e03053a484fa71e1c36590d7e39ed95 Mon Sep 17 00:00:00 2001 From: Paulb23 Date: Wed, 30 Jun 2021 11:58:13 +0100 Subject: Move brace matching into CodeEdit --- doc/classes/CodeEdit.xml | 3 +++ doc/classes/TextEdit.xml | 2 -- editor/code_editor.cpp | 2 +- scene/gui/code_edit.cpp | 13 +++++++++++++ scene/gui/code_edit.h | 3 +++ scene/gui/text_edit.cpp | 6 +++--- scene/gui/text_edit.h | 7 ++----- scene/resources/default_theme/default_theme.cpp | 1 - 8 files changed, 25 insertions(+), 12 deletions(-) (limited to 'doc/classes') diff --git a/doc/classes/CodeEdit.xml b/doc/classes/CodeEdit.xml index 1a6311c905..249334f416 100644 --- a/doc/classes/CodeEdit.xml +++ b/doc/classes/CodeEdit.xml @@ -420,6 +420,9 @@ Sets whether brace pairs should be autocompleted. + + Highlight mismatching brace pairs. + Sets the brace pairs to be autocompleted. diff --git a/doc/classes/TextEdit.xml b/doc/classes/TextEdit.xml index cc5c36bbd3..0b0d3d14a3 100644 --- a/doc/classes/TextEdit.xml +++ b/doc/classes/TextEdit.xml @@ -798,8 +798,6 @@ Sets the background [Color] of this [TextEdit]. - - diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 668d364f3a..6e1ac3e837 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -1825,7 +1825,7 @@ CodeTextEditor::CodeTextEditor() { } text_editor->set_draw_line_numbers(true); - text_editor->set_brace_matching(true); + text_editor->set_highlight_matching_braces_enabled(true); text_editor->set_auto_indent_enabled(true); status_bar = memnew(HBoxContainer); diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index e21f05c979..47ab3f82c1 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -937,6 +937,15 @@ bool CodeEdit::is_auto_brace_completion_enabled() const { return auto_brace_completion_enabled; } +void CodeEdit::set_highlight_matching_braces_enabled(bool p_enabled) { + highlight_matching_braces_enabled = p_enabled; + update(); +} + +bool CodeEdit::is_highlight_matching_braces_enabled() const { + return highlight_matching_braces_enabled; +} + void CodeEdit::add_auto_brace_completion_pair(const String &p_open_key, const String &p_close_key) { ERR_FAIL_COND_MSG(p_open_key.is_empty(), "auto brace completion open key cannot be empty"); ERR_FAIL_COND_MSG(p_close_key.is_empty(), "auto brace completion close key cannot be empty"); @@ -1881,6 +1890,9 @@ void CodeEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("set_auto_brace_completion_enabled", "enable"), &CodeEdit::set_auto_brace_completion_enabled); ClassDB::bind_method(D_METHOD("is_auto_brace_completion_enabled"), &CodeEdit::is_auto_brace_completion_enabled); + ClassDB::bind_method(D_METHOD("set_highlight_matching_braces_enabled", "enable"), &CodeEdit::set_highlight_matching_braces_enabled); + ClassDB::bind_method(D_METHOD("is_highlight_matching_braces_enabled"), &CodeEdit::is_highlight_matching_braces_enabled); + ClassDB::bind_method(D_METHOD("add_auto_brace_completion_pair", "start_key", "end_key"), &CodeEdit::add_auto_brace_completion_pair); ClassDB::bind_method(D_METHOD("set_auto_brace_completion_pairs", "pairs"), &CodeEdit::set_auto_brace_completion_pairs); ClassDB::bind_method(D_METHOD("get_auto_brace_completion_pairs"), &CodeEdit::get_auto_brace_completion_pairs); @@ -2048,6 +2060,7 @@ void CodeEdit::_bind_methods() { ADD_GROUP("Auto brace completion", "auto_brace_completion_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_brace_completion_enabled"), "set_auto_brace_completion_enabled", "is_auto_brace_completion_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_brace_completion_highlight_matching"), "set_highlight_matching_braces_enabled", "is_highlight_matching_braces_enabled"); ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "auto_brace_completion_pairs"), "set_auto_brace_completion_pairs", "get_auto_brace_completion_pairs"); /* Signals */ diff --git a/scene/gui/code_edit.h b/scene/gui/code_edit.h index 1795364b82..00958f2d06 100644 --- a/scene/gui/code_edit.h +++ b/scene/gui/code_edit.h @@ -259,6 +259,9 @@ public: void set_auto_brace_completion_enabled(bool p_enabled); bool is_auto_brace_completion_enabled() const; + void set_highlight_matching_braces_enabled(bool p_enabled); + bool is_highlight_matching_braces_enabled() const; + void add_auto_brace_completion_pair(const String &p_open_key, const String &p_close_key); void set_auto_brace_completion_pairs(const Dictionary &p_auto_brace_completion_pairs); Dictionary get_auto_brace_completion_pairs() const; diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 1c92916b33..f6711461ed 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -626,7 +626,7 @@ void TextEdit::_notification(int p_what) { bool brace_close_matching = false; bool brace_close_mismatch = false; - if (brace_matching_enabled && cursor.line >= 0 && cursor.line < text.size() && cursor.column >= 0) { + if (highlight_matching_braces_enabled && cursor.line >= 0 && cursor.line < text.size() && cursor.column >= 0) { if (cursor.column < text[cursor.line].length()) { // Check for open. char32_t c = text[cursor.line][cursor.column]; @@ -1269,7 +1269,7 @@ void TextEdit::_notification(int p_what) { int char_pos = char_ofs + char_margin + ofs_x; if (char_pos >= xmargin_beg) { - if (brace_matching_enabled) { + if (highlight_matching_braces_enabled) { if ((brace_open_match_line == line && brace_open_match_column == glyphs[j].start) || (cursor.column == glyphs[j].start && cursor.line == line && cursor_wrap_index == line_wrap_index && (brace_open_matching || brace_open_mismatch))) { if (brace_open_mismatch) { @@ -3838,7 +3838,7 @@ void TextEdit::_update_caches() { cache.current_line_color = get_theme_color(SNAME("current_line_color")); cache.line_length_guideline_color = get_theme_color(SNAME("line_length_guideline_color")); cache.code_folding_color = get_theme_color(SNAME("code_folding_color"), SNAME("CodeEdit")); - cache.brace_mismatch_color = get_theme_color(SNAME("brace_mismatch_color")); + cache.brace_mismatch_color = get_theme_color(SNAME("brace_mismatch_color"), SNAME("CodeEdit")); cache.word_highlighted_color = get_theme_color(SNAME("word_highlighted_color")); cache.search_result_color = get_theme_color(SNAME("search_result_color")); cache.search_result_border_color = get_theme_color(SNAME("search_result_border_color")); diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index 0ac5e0917b..c494b6399c 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -291,7 +291,6 @@ private: bool highlight_all_occurrences = false; bool scroll_past_end_of_file_enabled = false; - bool brace_matching_enabled = false; bool highlight_current_line = false; String cut_copy_line; @@ -433,6 +432,8 @@ private: void _move_cursor_document_end(bool p_select); protected: + bool highlight_matching_braces_enabled = false; + struct Cache { Ref tab_icon; Ref space_icon; @@ -628,10 +629,6 @@ public: scroll_past_end_of_file_enabled = p_enabled; update(); } - inline void set_brace_matching(bool p_enabled) { - brace_matching_enabled = p_enabled; - update(); - } void center_viewport_to_cursor(); diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index a4e126fcc6..9f14e5e276 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -457,7 +457,6 @@ void fill_default_theme(Ref &theme, const Ref &default_font, const theme->set_color("current_line_color", "TextEdit", Color(0.25, 0.25, 0.26, 0.8)); theme->set_color("caret_color", "TextEdit", control_font_color); theme->set_color("caret_background_color", "TextEdit", Color(0, 0, 0)); - theme->set_color("brace_mismatch_color", "TextEdit", Color(1, 0.2, 0.2)); theme->set_color("word_highlighted_color", "TextEdit", Color(0.8, 0.9, 0.9, 0.15)); theme->set_constant("line_spacing", "TextEdit", 4 * scale); -- cgit v1.2.3 From 8f900ac178acf4e9a5dae1e3a8c78f071debd282 Mon Sep 17 00:00:00 2001 From: Paulb23 Date: Wed, 30 Jun 2021 18:03:32 +0100 Subject: Move line length guidelines into CodeEdit --- doc/classes/CodeEdit.xml | 6 ++++ doc/classes/TextEdit.xml | 6 ++++ editor/code_editor.cpp | 12 ++++++-- scene/gui/code_edit.cpp | 37 +++++++++++++++++++++++ scene/gui/code_edit.h | 8 +++++ scene/gui/text_edit.cpp | 40 +------------------------ scene/gui/text_edit.h | 8 ----- scene/resources/default_theme/default_theme.cpp | 1 + 8 files changed, 68 insertions(+), 50 deletions(-) (limited to 'doc/classes') diff --git a/doc/classes/CodeEdit.xml b/doc/classes/CodeEdit.xml index 249334f416..b1c2c64e6c 100644 --- a/doc/classes/CodeEdit.xml +++ b/doc/classes/CodeEdit.xml @@ -464,6 +464,9 @@ Sets whether line folding is allowed. + + + Draws vertical lines at the provided columns. The first entry is considered a main hard guideline and is draw more prominently. @@ -568,6 +571,9 @@ Font size of the [CodeEdit]'s text. + + Color of the main line length guideline, secondary guidelines will have 50% alpha applied. + diff --git a/doc/classes/TextEdit.xml b/doc/classes/TextEdit.xml index 0b0d3d14a3..ada85d58d7 100644 --- a/doc/classes/TextEdit.xml +++ b/doc/classes/TextEdit.xml @@ -264,6 +264,12 @@ Returns the [TextEdit]'s' tab size. + + + + + + diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 6e1ac3e837..eeb99b3677 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -951,14 +951,20 @@ void CodeTextEditor::update_editor_settings() { text_editor->set_line_folding_enabled(EditorSettings::get_singleton()->get("text_editor/appearance/code_folding")); text_editor->set_draw_fold_gutter(EditorSettings::get_singleton()->get("text_editor/appearance/code_folding")); text_editor->set_wrap_enabled(EditorSettings::get_singleton()->get("text_editor/appearance/word_wrap")); - text_editor->set_show_line_length_guidelines(EditorSettings::get_singleton()->get("text_editor/appearance/show_line_length_guidelines")); - text_editor->set_line_length_guideline_soft_column(EditorSettings::get_singleton()->get("text_editor/appearance/line_length_guideline_soft_column")); - text_editor->set_line_length_guideline_hard_column(EditorSettings::get_singleton()->get("text_editor/appearance/line_length_guideline_hard_column")); text_editor->set_scroll_pass_end_of_file(EditorSettings::get_singleton()->get("text_editor/cursor/scroll_past_end_of_file")); text_editor->cursor_set_block_mode(EditorSettings::get_singleton()->get("text_editor/cursor/block_caret")); text_editor->cursor_set_blink_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink")); text_editor->cursor_set_blink_speed(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink_speed")); text_editor->set_auto_brace_completion_enabled(EditorSettings::get_singleton()->get("text_editor/completion/auto_brace_complete")); + + if (EditorSettings::get_singleton()->get("text_editor/appearance/show_line_length_guidelines")) { + TypedArray guideline_cols; + guideline_cols.append(EditorSettings::get_singleton()->get("text_editor/appearance/line_length_guideline_hard_column")); + if (EditorSettings::get_singleton()->get("text_editor/appearance/line_length_guideline_soft_column") != guideline_cols[0]) { + guideline_cols.append(EditorSettings::get_singleton()->get("text_editor/appearance/line_length_guideline_soft_column")); + } + text_editor->set_line_length_guidelines(guideline_cols); + } } void CodeTextEditor::set_find_replace_bar(FindReplaceBar *p_bar) { diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index 47ab3f82c1..10d7276d36 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -72,13 +72,34 @@ void CodeEdit::_notification(int p_what) { code_completion_background_color = get_theme_color(SNAME("completion_background_color")); code_completion_selected_color = get_theme_color(SNAME("completion_selected_color")); code_completion_existing_color = get_theme_color(SNAME("completion_existing_color")); + + line_length_guideline_color = get_theme_color(SNAME("line_length_guideline_color")); } break; case NOTIFICATION_DRAW: { RID ci = get_canvas_item(); + const Size2 size = get_size(); const bool caret_visible = is_caret_visible(); const bool rtl = is_layout_rtl(); const int row_height = get_row_height(); + if (line_length_guideline_columns.size() > 0) { + const int xmargin_beg = cache.style_normal->get_margin(SIDE_LEFT) + get_total_gutter_width(); + const int xmargin_end = size.width - cache.style_normal->get_margin(SIDE_RIGHT) - (is_drawing_minimap() ? get_minimap_width() : 0); + const int char_size = (int)cache.font->get_char_size('0', 0, cache.font_size).width; + + for (int i = 0; i < line_length_guideline_columns.size(); i++) { + const int xoffset = xmargin_beg + char_size * (int)line_length_guideline_columns[i] - get_h_scroll(); + if (xoffset > xmargin_beg && xoffset < xmargin_end) { + Color guideline_color = (i == 0) ? line_length_guideline_color : line_length_guideline_color * Color(1, 1, 1, 0.5); + if (rtl) { + RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2(size.width - xoffset, 0), Point2(size.width - xoffset, size.height), guideline_color); + continue; + } + RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2(xoffset, 0), Point2(xoffset, size.height), guideline_color); + } + } + } + bool code_completion_below = false; if (caret_visible && code_completion_active && code_completion_options.size() > 0) { Ref csb = get_theme_stylebox(SNAME("completion")); @@ -1866,6 +1887,16 @@ void CodeEdit::cancel_code_completion() { update(); } +/* Line length guidelines */ +void CodeEdit::set_line_length_guidelines(TypedArray p_guideline_columns) { + line_length_guideline_columns = p_guideline_columns; + update(); +} + +TypedArray CodeEdit::get_line_length_guidelines() const { + return line_length_guideline_columns; +} + void CodeEdit::_bind_methods() { /* Indent management */ ClassDB::bind_method(D_METHOD("set_indent_size", "size"), &CodeEdit::set_indent_size); @@ -2030,7 +2061,13 @@ void CodeEdit::_bind_methods() { BIND_VMETHOD(MethodInfo("_request_code_completion", PropertyInfo(Variant::BOOL, "force"))); BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_filter_code_completion_candidates", PropertyInfo(Variant::ARRAY, "candidates"))); + /* Line length guidelines */ + ClassDB::bind_method(D_METHOD("set_line_length_guidelines", "guideline_columns"), &CodeEdit::set_line_length_guidelines); + ClassDB::bind_method(D_METHOD("get_line_length_guidelines"), &CodeEdit::get_line_length_guidelines); + /* Inspector */ + ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "line_length_guidelines"), "set_line_length_guidelines", "get_line_length_guidelines"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_breakpoints_gutter"), "set_draw_breakpoints_gutter", "is_drawing_breakpoints_gutter"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_bookmarks"), "set_draw_bookmarks_gutter", "is_drawing_bookmarks_gutter"); diff --git a/scene/gui/code_edit.h b/scene/gui/code_edit.h index 00958f2d06..ac6f91b26d 100644 --- a/scene/gui/code_edit.h +++ b/scene/gui/code_edit.h @@ -223,6 +223,10 @@ private: void _lines_edited_from(int p_from_line, int p_to_line); + /* Line length guidelines */ + TypedArray line_length_guideline_columns; + Color line_length_guideline_color; + protected: void _gui_input(const Ref &p_gui_input) override; void _notification(int p_what); @@ -378,6 +382,10 @@ public: void confirm_code_completion(bool p_replace = false); void cancel_code_completion(); + /* Line length guidelines */ + void set_line_length_guidelines(TypedArray p_guideline_columns); + TypedArray get_line_length_guidelines() const; + CodeEdit(); ~CodeEdit(); }; diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index f6711461ed..85063ae88d 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -594,29 +594,6 @@ void TextEdit::_notification(int p_what) { RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(), get_size()), cache.background_color); } - if (line_length_guidelines) { - const int hard_x = xmargin_beg + (int)cache.font->get_char_size('0', 0, cache.font_size).width * line_length_guideline_hard_col - cursor.x_ofs; - if (hard_x > xmargin_beg && hard_x < xmargin_end) { - if (rtl) { - RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2(size.width - hard_x, 0), Point2(size.width - hard_x, size.height), cache.line_length_guideline_color); - } else { - RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2(hard_x, 0), Point2(hard_x, size.height), cache.line_length_guideline_color); - } - } - - // Draw a "Soft" line length guideline, less visible than the hard line length guideline. - // It's usually set to a lower column compared to the hard line length guideline. - // Only drawn if its column differs from the hard line length guideline. - const int soft_x = xmargin_beg + (int)cache.font->get_char_size('0', 0, cache.font_size).width * line_length_guideline_soft_col - cursor.x_ofs; - if (hard_x != soft_x && soft_x > xmargin_beg && soft_x < xmargin_end) { - if (rtl) { - RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2(size.width - soft_x, 0), Point2(size.width - soft_x, size.height), cache.line_length_guideline_color * Color(1, 1, 1, 0.5)); - } else { - RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2(soft_x, 0), Point2(soft_x, size.height), cache.line_length_guideline_color * Color(1, 1, 1, 0.5)); - } - } - } - int brace_open_match_line = -1; int brace_open_match_column = -1; bool brace_open_matching = false; @@ -3836,7 +3813,6 @@ void TextEdit::_update_caches() { cache.font_readonly_color = get_theme_color(SNAME("font_readonly_color")); cache.selection_color = get_theme_color(SNAME("selection_color")); cache.current_line_color = get_theme_color(SNAME("current_line_color")); - cache.line_length_guideline_color = get_theme_color(SNAME("line_length_guideline_color")); cache.code_folding_color = get_theme_color(SNAME("code_folding_color"), SNAME("CodeEdit")); cache.brace_mismatch_color = get_theme_color(SNAME("brace_mismatch_color"), SNAME("CodeEdit")); cache.word_highlighted_color = get_theme_color(SNAME("word_highlighted_color")); @@ -5145,21 +5121,6 @@ void TextEdit::insert_at(const String &p_text, int at) { } } -void TextEdit::set_show_line_length_guidelines(bool p_show) { - line_length_guidelines = p_show; - update(); -} - -void TextEdit::set_line_length_guideline_soft_column(int p_column) { - line_length_guideline_soft_col = p_column; - update(); -} - -void TextEdit::set_line_length_guideline_hard_column(int p_column) { - line_length_guideline_hard_col = p_column; - update(); -} - void TextEdit::set_draw_minimap(bool p_draw) { if (draw_minimap != p_draw) { draw_minimap = p_draw; @@ -5599,6 +5560,7 @@ void TextEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("is_gutter_overwritable", "gutter"), &TextEdit::is_gutter_overwritable); ClassDB::bind_method(D_METHOD("merge_gutters", "from_line", "to_line"), &TextEdit::merge_gutters); ClassDB::bind_method(D_METHOD("set_gutter_custom_draw", "column", "object", "callback"), &TextEdit::set_gutter_custom_draw); + ClassDB::bind_method(D_METHOD("get_total_gutter_width"), &TextEdit::get_total_gutter_width); // Line gutters. ClassDB::bind_method(D_METHOD("set_line_gutter_metadata", "line", "gutter", "metadata"), &TextEdit::set_line_gutter_metadata); diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index c494b6399c..e8235a37f5 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -280,9 +280,6 @@ private: bool cursor_changed_dirty = false; bool text_changed_dirty = false; bool undo_enabled = true; - bool line_length_guidelines = false; - int line_length_guideline_soft_col = 80; - int line_length_guideline_hard_col = 100; bool hiding_enabled = false; bool draw_minimap = false; int minimap_width = 80; @@ -453,7 +450,6 @@ protected: Color selection_color; Color code_folding_color; Color current_line_color; - Color line_length_guideline_color; Color brace_mismatch_color; Color word_highlighted_color; Color search_result_color; @@ -739,10 +735,6 @@ public: void set_highlight_current_line(bool p_enabled); bool is_highlight_current_line_enabled() const; - void set_show_line_length_guidelines(bool p_show); - void set_line_length_guideline_soft_column(int p_column); - void set_line_length_guideline_hard_column(int p_column); - void set_draw_minimap(bool p_draw); bool is_drawing_minimap() const; diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 9f14e5e276..ad589d94d6 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -503,6 +503,7 @@ void fill_default_theme(Ref &theme, const Ref &default_font, const theme->set_color("line_number_color", "CodeEdit", Color(0.67, 0.67, 0.67, 0.4)); theme->set_color("safe_line_number_color", "CodeEdit", Color(0.67, 0.78, 0.67, 0.6)); theme->set_color("word_highlighted_color", "CodeEdit", Color(0.8, 0.9, 0.9, 0.15)); + theme->set_color("line_length_guideline_color", "CodeEdit", Color(0.3, 0.5, 0.8, 0.1)); theme->set_constant("completion_lines", "CodeEdit", 7); theme->set_constant("completion_max_width", "CodeEdit", 50); -- cgit v1.2.3 From dd5a37f556ea2db443f65a82228e416ca5491772 Mon Sep 17 00:00:00 2001 From: Paulb23 Date: Thu, 1 Jul 2021 17:10:54 +0100 Subject: Move symbol lookup into CodeEdit --- doc/classes/CodeEdit.xml | 38 ++++++++++- doc/classes/TextEdit.xml | 18 ++--- editor/plugins/script_text_editor.cpp | 17 +++-- editor/plugins/shader_editor_plugin.cpp | 2 +- scene/gui/code_edit.cpp | 115 ++++++++++++++++++++++++++++++++ scene/gui/code_edit.h | 14 ++++ scene/gui/text_edit.cpp | 94 ++++---------------------- scene/gui/text_edit.h | 13 ++-- 8 files changed, 198 insertions(+), 113 deletions(-) (limited to 'doc/classes') diff --git a/doc/classes/CodeEdit.xml b/doc/classes/CodeEdit.xml index b1c2c64e6c..d22ba65421 100644 --- a/doc/classes/CodeEdit.xml +++ b/doc/classes/CodeEdit.xml @@ -240,6 +240,13 @@ Returns the full text with char [code]0xFFFF[/code] at the caret location. + + + + + Returns the full text with char [code]0xFFFF[/code] at the cursor location. + + @@ -382,6 +389,15 @@ + + + + + + + Sets the symbol emitted by [signal symbol_validate] as a valid lookup. + + @@ -466,8 +482,10 @@ - Draws vertical lines at the provided columns. The first entry is considered a main hard guideline and is draw more prominently. + + Set when a validated word from [signal symbol_validate] is clicked, the [signal symbol_lookup] should be emitted. + @@ -483,6 +501,24 @@ Emitted when the user requests code completion. + + + + + + + + + Emitted when the user has clicked on a valid symbol. + + + + + + + Emitted when the user hovers over a symbol. The symbol should be validated and responded to, by calling [method set_symbol_lookup_word_as_valid]. + + diff --git a/doc/classes/TextEdit.xml b/doc/classes/TextEdit.xml index ada85d58d7..62c33e9436 100644 --- a/doc/classes/TextEdit.xml +++ b/doc/classes/TextEdit.xml @@ -295,6 +295,12 @@ Returns [code]true[/code] if the caret is visible on the screen. + + + + + + @@ -668,18 +674,6 @@ - - - - - - - - - - - - Emitted when the text changes. diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 1d636f1c48..6670206647 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -750,7 +750,7 @@ void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_c EditorNode::get_singleton()->load_resource(p_symbol); } - } else if (script->get_language()->lookup_code(code_editor->get_text_editor()->get_text_for_lookup_completion(), p_symbol, script->get_path(), base, result) == OK) { + } else if (script->get_language()->lookup_code(code_editor->get_text_editor()->get_text_for_symbol_lookup(), p_symbol, script->get_path(), base, result) == OK) { _goto_line(p_row); result.class_name = result.class_name.trim_prefix("_"); @@ -853,18 +853,17 @@ void ScriptTextEditor::_validate_symbol(const String &p_symbol) { } ScriptLanguage::LookupResult result; - if (ScriptServer::is_global_class(p_symbol) || p_symbol.is_resource_file() || script->get_language()->lookup_code(code_editor->get_text_editor()->get_text_for_lookup_completion(), p_symbol, script->get_path(), base, result) == OK || (ProjectSettings::get_singleton()->has_autoload(p_symbol) && ProjectSettings::get_singleton()->get_autoload(p_symbol).is_singleton)) { - text_edit->set_highlighted_word(p_symbol); + if (ScriptServer::is_global_class(p_symbol) || p_symbol.is_resource_file() || script->get_language()->lookup_code(code_editor->get_text_editor()->get_text_for_symbol_lookup(), p_symbol, script->get_path(), base, result) == OK || (ProjectSettings::get_singleton()->has_autoload(p_symbol) && ProjectSettings::get_singleton()->get_autoload(p_symbol).is_singleton)) { + text_edit->set_symbol_lookup_word_as_valid(true); } else if (p_symbol.is_rel_path()) { String path = _get_absolute_path(p_symbol); if (FileAccess::exists(path)) { - text_edit->set_highlighted_word(p_symbol); + text_edit->set_symbol_lookup_word_as_valid(true); } else { - text_edit->set_highlighted_word(String()); + text_edit->set_symbol_lookup_word_as_valid(false); } - } else { - text_edit->set_highlighted_word(String()); + text_edit->set_symbol_lookup_word_as_valid(false); } } @@ -1552,7 +1551,7 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref &ev) { base = _find_node_for_script(base, base, script); } ScriptLanguage::LookupResult result; - if (script->get_language()->lookup_code(code_editor->get_text_editor()->get_text_for_lookup_completion(), word_at_pos, script->get_path(), base, result) == OK) { + if (script->get_language()->lookup_code(code_editor->get_text_editor()->get_text_for_symbol_lookup(), word_at_pos, script->get_path(), base, result) == OK) { open_docs = true; } } @@ -1837,7 +1836,7 @@ ScriptTextEditor::ScriptTextEditor() { code_editor->get_text_editor()->set_code_hint_draw_below(EditorSettings::get_singleton()->get("text_editor/completion/put_callhint_tooltip_below_current_line")); - code_editor->get_text_editor()->set_select_identifiers_on_hover(true); + code_editor->get_text_editor()->set_symbol_lookup_on_click_enabled(true); code_editor->get_text_editor()->set_context_menu_enabled(false); context_menu = memnew(PopupMenu); diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index bb91f812e4..95973f9dfd 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -663,7 +663,7 @@ ShaderEditor::ShaderEditor(EditorNode *p_node) { shader_editor->get_text_editor()->set_code_hint_draw_below(EditorSettings::get_singleton()->get("text_editor/completion/put_callhint_tooltip_below_current_line")); - shader_editor->get_text_editor()->set_select_identifiers_on_hover(true); + shader_editor->get_text_editor()->set_symbol_lookup_on_click_enabled(true); shader_editor->get_text_editor()->set_context_menu_enabled(false); shader_editor->get_text_editor()->connect("gui_input", callable_mp(this, &ShaderEditor::_text_edit_gui_input)); diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index 10d7276d36..d76597b1c9 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -299,6 +299,39 @@ void CodeEdit::_gui_input(const Ref &p_gui_input) { } } } + } else { + if (mb->get_button_index() == MOUSE_BUTTON_LEFT) { + if (mb->is_command_pressed() && symbol_lookup_word != String()) { + Vector2i mpos = mb->get_position(); + if (is_layout_rtl()) { + mpos.x = get_size().x - mpos.x; + } + int line, col; + _get_mouse_pos(Point2i(mpos.x, mpos.y), line, col); + + emit_signal(SNAME("symbol_lookup"), symbol_lookup_word, line, col); + return; + } + } + } + } + + Ref mm = p_gui_input; + if (mm.is_valid()) { + Vector2i mpos = mm->get_position(); + if (is_layout_rtl()) { + mpos.x = get_size().x - mpos.x; + } + + if (symbol_lookup_on_click_enabled) { + if (mm->is_command_pressed() && mm->get_button_mask() == 0 && !is_dragging_cursor()) { + symbol_lookup_new_word = get_word_at_pos(mpos); + if (symbol_lookup_new_word != symbol_lookup_word) { + emit_signal(SNAME("symbol_validate"), symbol_lookup_new_word); + } + } else { + set_symbol_lookup_word_as_valid(false); + } } } @@ -309,6 +342,25 @@ void CodeEdit::_gui_input(const Ref &p_gui_input) { return; } + /* Ctrl + Hover symbols */ +#ifdef OSX_ENABLED + if (k->get_keycode() == KEY_META) { +#else + if (k->get_keycode() == KEY_CTRL) { +#endif + if (symbol_lookup_on_click_enabled) { + if (k->is_pressed() && !is_dragging_cursor()) { + symbol_lookup_new_word = get_word_at_pos(_get_local_mouse_pos()); + if (symbol_lookup_new_word != symbol_lookup_word) { + emit_signal(SNAME("symbol_validate"), symbol_lookup_new_word); + } + } else { + set_symbol_lookup_word_as_valid(false); + } + } + return; + } + /* If a modifier has been pressed, and nothing else, return. */ if (!k->is_pressed() || k->get_keycode() == KEY_CTRL || k->get_keycode() == KEY_ALT || k->get_keycode() == KEY_SHIFT || k->get_keycode() == KEY_META) { return; @@ -460,6 +512,10 @@ void CodeEdit::_gui_input(const Ref &p_gui_input) { /* General overrides */ Control::CursorShape CodeEdit::get_cursor_shape(const Point2 &p_pos) const { + if (symbol_lookup_word != String()) { + return CURSOR_POINTING_HAND; + } + if ((code_completion_active && code_completion_rect.has_point(p_pos)) || (is_readonly() && (!is_selecting_enabled() || get_line_count() == 0))) { return CURSOR_ARROW; } @@ -1897,6 +1953,48 @@ TypedArray CodeEdit::get_line_length_guidelines() const { return line_length_guideline_columns; } +/* Symbol lookup */ +void CodeEdit::set_symbol_lookup_on_click_enabled(bool p_enabled) { + symbol_lookup_on_click_enabled = p_enabled; + set_symbol_lookup_word_as_valid(false); +} + +bool CodeEdit::is_symbol_lookup_on_click_enabled() const { + return symbol_lookup_on_click_enabled; +} + +String CodeEdit::get_text_for_symbol_lookup() { + int line, col; + Point2i mp = _get_local_mouse_pos(); + _get_mouse_pos(mp, line, col); + + StringBuilder lookup_text; + const int text_size = get_line_count(); + for (int i = 0; i < text_size; i++) { + String text = get_line(i); + + if (i == line) { + lookup_text += text.substr(0, col); + /* Not unicode, represents the cursor. */ + lookup_text += String::chr(0xFFFF); + lookup_text += text.substr(col, text.size()); + } else { + lookup_text += text; + } + + if (i != text_size - 1) { + lookup_text += "\n"; + } + } + return lookup_text.as_string(); +} + +void CodeEdit::set_symbol_lookup_word_as_valid(bool p_valid) { + symbol_lookup_word = p_valid ? symbol_lookup_new_word : ""; + symbol_lookup_new_word = ""; + _set_symbol_lookup_word(symbol_lookup_word); +} + void CodeEdit::_bind_methods() { /* Indent management */ ClassDB::bind_method(D_METHOD("set_indent_size", "size"), &CodeEdit::set_indent_size); @@ -2065,7 +2163,17 @@ void CodeEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("set_line_length_guidelines", "guideline_columns"), &CodeEdit::set_line_length_guidelines); ClassDB::bind_method(D_METHOD("get_line_length_guidelines"), &CodeEdit::get_line_length_guidelines); + /* Symbol lookup */ + ClassDB::bind_method(D_METHOD("set_symbol_lookup_on_click_enabled", "enable"), &CodeEdit::set_symbol_lookup_on_click_enabled); + ClassDB::bind_method(D_METHOD("is_symbol_lookup_on_click_enabled"), &CodeEdit::is_symbol_lookup_on_click_enabled); + + ClassDB::bind_method(D_METHOD("get_text_for_symbol_lookup"), &CodeEdit::get_text_for_symbol_lookup); + + ClassDB::bind_method(D_METHOD("set_symbol_lookup_word_as_valid", "valid"), &CodeEdit::set_symbol_lookup_word_as_valid); + /* Inspector */ + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "symbol_lookup_on_click"), "set_symbol_lookup_on_click_enabled", "is_symbol_lookup_on_click_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "line_length_guidelines"), "set_line_length_guidelines", "get_line_length_guidelines"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_breakpoints_gutter"), "set_draw_breakpoints_gutter", "is_drawing_breakpoints_gutter"); @@ -2101,8 +2209,15 @@ void CodeEdit::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "auto_brace_completion_pairs"), "set_auto_brace_completion_pairs", "get_auto_brace_completion_pairs"); /* Signals */ + /* Gutters */ ADD_SIGNAL(MethodInfo("breakpoint_toggled", PropertyInfo(Variant::INT, "line"))); + + /* Code Completion */ ADD_SIGNAL(MethodInfo("request_code_completion")); + + /* Symbol lookup */ + ADD_SIGNAL(MethodInfo("symbol_lookup", PropertyInfo(Variant::STRING, "symbol"), PropertyInfo(Variant::INT, "line"), PropertyInfo(Variant::INT, "column"))); + ADD_SIGNAL(MethodInfo("symbol_validate", PropertyInfo(Variant::STRING, "symbol"))); } /* Auto brace completion */ diff --git a/scene/gui/code_edit.h b/scene/gui/code_edit.h index ac6f91b26d..efd778ffb3 100644 --- a/scene/gui/code_edit.h +++ b/scene/gui/code_edit.h @@ -227,6 +227,12 @@ private: TypedArray line_length_guideline_columns; Color line_length_guideline_color; + /* Symbol lookup */ + bool symbol_lookup_on_click_enabled = false; + + String symbol_lookup_new_word = ""; + String symbol_lookup_word = ""; + protected: void _gui_input(const Ref &p_gui_input) override; void _notification(int p_what); @@ -386,6 +392,14 @@ public: void set_line_length_guidelines(TypedArray p_guideline_columns); TypedArray get_line_length_guidelines() const; + /* Symbol lookup */ + void set_symbol_lookup_on_click_enabled(bool p_enabled); + bool is_symbol_lookup_on_click_enabled() const; + + String get_text_for_symbol_lookup(); + + void set_symbol_lookup_word_as_valid(bool p_valid); + CodeEdit(); ~CodeEdit(); }; diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 85063ae88d..1b3935dd25 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1177,11 +1177,11 @@ void TextEdit::_notification(int p_what) { } } - if (!clipped && select_identifiers_enabled && highlighted_word.length() != 0) { // Highlight word - if (_is_char(highlighted_word[0]) || highlighted_word[0] == '.') { - int highlighted_word_col = _get_column_pos_of_word(highlighted_word, str, SEARCH_MATCH_CASE | SEARCH_WHOLE_WORDS, 0); + if (!clipped && lookup_symbol_word.length() != 0) { // Highlight word + if (_is_char(lookup_symbol_word[0]) || lookup_symbol_word[0] == '.') { + int highlighted_word_col = _get_column_pos_of_word(lookup_symbol_word, str, SEARCH_MATCH_CASE | SEARCH_WHOLE_WORDS, 0); while (highlighted_word_col != -1) { - Vector sel = TS->shaped_text_get_selection(rid, highlighted_word_col + start, highlighted_word_col + highlighted_word.length() + start); + Vector sel = TS->shaped_text_get_selection(rid, highlighted_word_col + start, highlighted_word_col + lookup_symbol_word.length() + start); for (int j = 0; j < sel.size(); j++) { Rect2 rect = Rect2(sel[j].x + char_margin + ofs_x, ofs_y, sel[j].y - sel[j].x, row_height); if (rect.position.x + rect.size.x <= xmargin_beg || rect.position.x > xmargin_end) { @@ -1198,7 +1198,7 @@ void TextEdit::_notification(int p_what) { draw_rect(rect, cache.font_selected_color); } - highlighted_word_col = _get_column_pos_of_word(highlighted_word, str, SEARCH_MATCH_CASE | SEARCH_WHOLE_WORDS, highlighted_word_col + 1); + highlighted_word_col = _get_column_pos_of_word(lookup_symbol_word, str, SEARCH_MATCH_CASE | SEARCH_WHOLE_WORDS, highlighted_word_col + 1); } } } @@ -2112,6 +2112,10 @@ void TextEdit::_get_minimap_mouse_row(const Point2i &p_mouse, int &r_row) const r_row = row; } +bool TextEdit::is_dragging_cursor() const { + return dragging_selection || dragging_minimap; +} + void TextEdit::_gui_input(const Ref &p_gui_input) { ERR_FAIL_COND(p_gui_input.is_null()); @@ -2289,14 +2293,6 @@ void TextEdit::_gui_input(const Ref &p_gui_input) { } } else { if (mb->get_button_index() == MOUSE_BUTTON_LEFT) { - if (mb->is_command_pressed() && highlighted_word != String()) { - int row, col; - _get_mouse_pos(Point2i(mpos.x, mpos.y), row, col); - - emit_signal(SNAME("symbol_lookup"), highlighted_word, row, col); - return; - } - dragging_minimap = false; dragging_selection = false; can_drag_minimap = false; @@ -2331,18 +2327,6 @@ void TextEdit::_gui_input(const Ref &p_gui_input) { if (is_layout_rtl()) { mpos.x = get_size().x - mpos.x; } - if (select_identifiers_enabled) { - if (!dragging_minimap && !dragging_selection && mm->is_command_pressed() && mm->get_button_mask() == 0) { - String new_word = get_word_at_pos(mpos); - if (new_word != highlighted_word) { - emit_signal(SNAME("symbol_validate"), new_word); - } - } else { - if (highlighted_word != String()) { - set_highlighted_word(String()); - } - } - } if (mm->get_button_mask() & MOUSE_BUTTON_MASK_LEFT && get_viewport()->gui_get_drag_data() == Variant()) { // Ignore if dragging. _reset_caret_blink_timer(); @@ -2377,23 +2361,6 @@ void TextEdit::_gui_input(const Ref &p_gui_input) { Ref k = p_gui_input; if (k.is_valid()) { - // Ctrl + Hover symbols -#ifdef OSX_ENABLED - if (k->get_keycode() == KEY_META) { -#else - if (k->get_keycode() == KEY_CTRL) { -#endif - if (select_identifiers_enabled) { - if (k->is_pressed() && !dragging_minimap && !dragging_selection) { - Point2 mp = _get_local_mouse_pos(); - emit_signal(SNAME("symbol_validate"), get_word_at_pos(mp)); - } else { - set_highlighted_word(String()); - } - } - return; - } - if (!k->is_pressed()) { return; } @@ -3515,10 +3482,6 @@ void TextEdit::insert_text_at_cursor(const String &p_text) { } Control::CursorShape TextEdit::get_cursor_shape(const Point2 &p_pos) const { - if (highlighted_word != String()) { - return CURSOR_POINTING_HAND; - } - int row, col; _get_mouse_pos(p_pos, row, col); @@ -3701,30 +3664,6 @@ bool TextEdit::get_draw_control_chars() const { return draw_control_chars; } -String TextEdit::get_text_for_lookup_completion() { - int row, col; - Point2i mp = _get_local_mouse_pos(); - _get_mouse_pos(mp, row, col); - - String longthing; - int len = text.size(); - for (int i = 0; i < len; i++) { - if (i == row) { - longthing += text[i].substr(0, col); - longthing += String::chr(0xFFFF); // Not unicode, represents the cursor. - longthing += text[i].substr(col, text[i].size()); - } else { - longthing += text[i]; - } - - if (i != len - 1) { - longthing += "\n"; - } - } - - return longthing; -} - String TextEdit::get_line(int line) const { if (line < 0 || line >= text.size()) { return ""; @@ -5297,19 +5236,11 @@ void TextEdit::menu_option(int p_option) { } } -void TextEdit::set_highlighted_word(const String &new_word) { - highlighted_word = new_word; +void TextEdit::_set_symbol_lookup_word(const String &p_symbol) { + lookup_symbol_word = p_symbol; update(); } -void TextEdit::set_select_identifiers_on_hover(bool p_enable) { - select_identifiers_enabled = p_enable; -} - -bool TextEdit::is_selecting_identifiers_on_hover_enabled() const { - return select_identifiers_enabled; -} - void TextEdit::set_context_menu_enabled(bool p_enable) { context_menu_enabled = p_enable; } @@ -5510,6 +5441,7 @@ void TextEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("select", "from_line", "from_column", "to_line", "to_column"), &TextEdit::select); ClassDB::bind_method(D_METHOD("select_all"), &TextEdit::select_all); ClassDB::bind_method(D_METHOD("deselect"), &TextEdit::deselect); + ClassDB::bind_method(D_METHOD("is_dragging_cursor"), &TextEdit::is_dragging_cursor); ClassDB::bind_method(D_METHOD("is_selection_active"), &TextEdit::is_selection_active); ClassDB::bind_method(D_METHOD("get_selection_from_line"), &TextEdit::get_selection_from_line); @@ -5642,8 +5574,6 @@ void TextEdit::_bind_methods() { ADD_SIGNAL(MethodInfo("gutter_clicked", PropertyInfo(Variant::INT, "line"), PropertyInfo(Variant::INT, "gutter"))); ADD_SIGNAL(MethodInfo("gutter_added")); ADD_SIGNAL(MethodInfo("gutter_removed")); - ADD_SIGNAL(MethodInfo("symbol_lookup", PropertyInfo(Variant::STRING, "symbol"), PropertyInfo(Variant::INT, "row"), PropertyInfo(Variant::INT, "column"))); - ADD_SIGNAL(MethodInfo("symbol_validate", PropertyInfo(Variant::STRING, "symbol"))); BIND_ENUM_CONSTANT(MENU_CUT); BIND_ENUM_CONSTANT(MENU_COPY); diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index e8235a37f5..9e6dedb267 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -305,7 +305,7 @@ private: float target_v_scroll = 0.0; float v_scroll_speed = 80.0; - String highlighted_word; + String lookup_symbol_word; uint64_t last_dblclk = 0; @@ -382,7 +382,6 @@ private: Size2 get_minimum_size() const override; int _get_control_height() const; - Point2 _get_local_mouse_pos() const; int _get_menu_action_accelerator(const String &p_action); void _reset_caret_blink_timer(); @@ -473,6 +472,8 @@ protected: bool _get(const StringName &p_name, Variant &r_ret) const; void _get_property_list(List *p_list) const; + void _set_symbol_lookup_word(const String &p_symbol); + public: /* Syntax Highlighting. */ Ref get_syntax_highlighter(); @@ -567,8 +568,10 @@ public: virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const override; + Point2 _get_local_mouse_pos() const; void _get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) const; void _get_minimap_mouse_row(const Point2i &p_mouse, int &r_row) const; + bool is_dragging_cursor() const; //void delete_char(); //void delete_line(); @@ -597,7 +600,6 @@ public: void set_structured_text_bidi_override_options(Array p_args); Array get_structured_text_bidi_override_options() const; - void set_highlighted_word(const String &new_word); void set_text(String p_text); void insert_text_at_cursor(const String &p_text); void insert_at(const String &p_text, int at); @@ -746,9 +748,6 @@ public: void set_tooltip_request_func(Object *p_obj, const StringName &p_function, const Variant &p_udata); - void set_select_identifiers_on_hover(bool p_enable); - bool is_selecting_identifiers_on_hover_enabled() const; - void set_context_menu_enabled(bool p_enable); bool is_context_menu_enabled(); @@ -764,8 +763,6 @@ public: bool is_menu_visible() const; PopupMenu *get_menu() const; - String get_text_for_lookup_completion(); - virtual bool is_text_field() const override; TextEdit(); ~TextEdit(); -- cgit v1.2.3 From 809a32c045e62280e89e9c4513d98f3c006f7be5 Mon Sep 17 00:00:00 2001 From: Paulb23 Date: Thu, 1 Jul 2021 17:40:59 +0100 Subject: Clean up and complete CodeEdit inspector and docs --- doc/classes/CodeEdit.xml | 142 ++++++++++++++++-------- doc/classes/TextEdit.xml | 12 +- editor/plugins/script_text_editor.cpp | 4 +- scene/gui/code_edit.cpp | 20 ++-- scene/gui/code_edit.h | 2 +- scene/resources/default_theme/default_theme.cpp | 1 - 6 files changed, 117 insertions(+), 64 deletions(-) (limited to 'doc/classes') diff --git a/doc/classes/CodeEdit.xml b/doc/classes/CodeEdit.xml index d22ba65421..0b060ec277 100644 --- a/doc/classes/CodeEdit.xml +++ b/doc/classes/CodeEdit.xml @@ -1,8 +1,10 @@ + Multiline text control intended for editing code. + CodeEdit is a specialised [TextEdit] designed for editing plain text code files. It contains a bunch of features commonly found in code editors such as line numbers, line folding, code completion, indent management and string / comment management. [b]Note[/b]: By default [CodeEdit] always use left-to-right text direction to correctly display source code. @@ -31,12 +33,9 @@ - - - - - - + + + Adds a brace pair. Both the start and end keys must be symbols. Only the start key has to be unique. @@ -93,11 +92,13 @@ + Clears all bookmarked lines. + Clears all breakpointed lines. @@ -109,6 +110,7 @@ + Clears all executed lines. @@ -150,10 +152,8 @@ - - - - + + Gets the matching auto brace close key for [code]open_key[/code]. @@ -161,11 +161,13 @@ + Gets all bookmarked lines. + Gets all breakpointed lines. @@ -226,6 +228,7 @@ + Gets all executing lines. @@ -241,26 +244,21 @@ - - + Returns the full text with char [code]0xFFFF[/code] at the cursor location. - - - - + + Returns [code]true[/code] if close key [code]close_key[/code] exists. - - - - + + Returns [code]true[/code] if open key [code]open_key[/code] exists. @@ -305,18 +303,21 @@ + Returns whether the line at the specified index is bookmarked or not. + Returns whether the line at the specified index is breakpointed or not. + Returns whether the line at the specified index is marked as executing or not. @@ -373,6 +374,7 @@ + Sets the line as bookmarked. @@ -380,6 +382,7 @@ + Sets the line as breakpointed. @@ -387,13 +390,12 @@ + Sets the line as executing. - - - - + + Sets the symbol emitted by [signal symbol_validate] as a valid lookup. @@ -408,6 +410,7 @@ + Unfolds all lines, folded or not. @@ -451,18 +454,26 @@ Sets the comment delimiters. All existing comment delimiters will be removed. - + Sets the string delimiters. All existing string delimiters will be removed. - + + Sets if bookmarked should be drawn in the gutter. This gutter is shared with breakpoints and executing lines. + + + Sets if breakpoints should be drawn in the gutter. This gutter is shared with bookmarks and executing lines. - + + Sets if executing lines should be marked in the gutter. This gutter is shared with breakpoints and bookmarks lines. - + + Sets if foldable lines icons should be drawn in the gutter. - + + Sets if line numbers should be drawn in the gutter. - + + Sets if line numbers drawn in the gutter are zero padded. Sets whether automatic indent are enabled, this will add an extra indent if a prefix or brace is found. @@ -477,23 +488,23 @@ Use spaces instead of tabs for indentation. - + Sets whether line folding is allowed. + Draws vertical lines at the provided columns. The first entry is considered a main hard guideline and is draw more prominently Set when a validated word from [signal symbol_validate] is clicked, the [signal symbol_lookup] should be emitted. - - + Emitted when a breakpoint is added or removed from a line. If the line is moved via backspace a removed is emitted at the old line. @@ -502,19 +513,15 @@ - - - - - - + + + Emitted when the user has clicked on a valid symbol. - - + Emitted when the user hovers over a symbol. The symbol should be validated and responded to, by calling [method set_symbol_lookup_word_as_valid]. @@ -522,114 +529,159 @@ + Marks the option as a class. + Marks the option as a function. + Marks the option as a Godot signal. + Marks the option as a variable. + Marks the option as a member. + Marks the option as a enum entry. + Marks the option as a constant. + Marks the option as a Godot node path. + Marks the option as a file path. + Marks the option as unclassified or plain text. + Sets the background [Color]. + Sets a custom [Texture2D] to draw in the bookmark gutter for bookmarked lines. + [Color] of the bookmark icon for bookmarked lines. + [Color] of the text to highlight mismatched braces. + Sets a custom [Texture2D] to draw in the breakpoint gutter for breakpointed lines. + [Color] of the breakpoint icon for bookmarked lines. + Sets a custom [Texture2D] to draw in the line folding gutter when a line can be folded. + [Color] of the text behind the caret when block caret is enabled. + [Color] of the caret. + [Color] for all icons related to line folding. + [StyleBox] for the code completion popup. + Sets the background [Color] for the code completion popup. + Background highlight [Color] for matching text in code completion options. + Font [Color] for the code completion popup. + Max number of options to display in the code completion popup at any one time. + Max width of options in the code completion popup. Options longer then this will be cut off. + [Color] of the scrollbar in the code completion popup. + Width of the scrollbar in the code completion popup. + Background highlight [Color] for the current selected option item in the code completion popup. + Background [Color] of the line containing the caret. + Icon to draw in the executing gutter for executing lines. + [Color] of the executing icon for executing lines. + Sets the [StyleBox] when in focus. + Sets a custom [Texture2D] to draw in the line folding gutter when a line is folded and can be unfolded. + Sets a custom [Texture2D] to draw at the end of a folded line. + Sets the default [Font]. + Sets the font [Color]. The tint of text outline of the [CodeEdit]. + Sets the font [Color] when [member readonly] is enabled. + Sets the [Color] of the selected text. [member override_selected_font_color] has to be enabled. - Font size of the [CodeEdit]'s text. + Sets default font size. - Color of the main line length guideline, secondary guidelines will have 50% alpha applied. + [Color] of the main line length guideline, secondary guidelines will have 50% alpha applied. + Sets the [Color] of line numbers. + Sets the spacing between the lines. + Sets the [StyleBox]. The size of the text outline. - - + Sets the [StyleBox] when [member readonly] is enabled. + Sets the highlight [Color] of text selections. + Sets a custom [Texture2D] for space text characters. + Sets a custom [Texture2D] for tab text characters. + Sets the highlight [Color] of multiple occurrences. [member highlight_all_occurrences] has to be enabled. diff --git a/doc/classes/TextEdit.xml b/doc/classes/TextEdit.xml index 62c33e9436..5d62050a94 100644 --- a/doc/classes/TextEdit.xml +++ b/doc/classes/TextEdit.xml @@ -17,10 +17,8 @@ - - - - + + @@ -265,8 +263,7 @@ - - + @@ -296,8 +293,7 @@ - - + diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 6670206647..5bbe56a800 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -204,7 +204,9 @@ void ScriptTextEditor::_set_theme_for_script() { for (const String &string : strings) { String beg = string.get_slice(" ", 0); String end = string.get_slice_count(" ") > 1 ? string.get_slice(" ", 1) : String(); - text_edit->add_string_delimiter(beg, end, end == ""); + if (!text_edit->has_string_delimiter(beg)) { + text_edit->add_string_delimiter(beg, end, end == ""); + } if (!end.is_empty() && !text_edit->has_auto_brace_completion_open_key(beg)) { text_edit->add_auto_brace_completion_pair(beg, end); diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index d76597b1c9..45d74c631a 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -2173,21 +2173,21 @@ void CodeEdit::_bind_methods() { /* Inspector */ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "symbol_lookup_on_click"), "set_symbol_lookup_on_click_enabled", "is_symbol_lookup_on_click_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "line_folding"), "set_line_folding_enabled", "is_line_folding_enabled"); ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "line_length_guidelines"), "set_line_length_guidelines", "get_line_length_guidelines"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_breakpoints_gutter"), "set_draw_breakpoints_gutter", "is_drawing_breakpoints_gutter"); - - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_bookmarks"), "set_draw_bookmarks_gutter", "is_drawing_bookmarks_gutter"); + ADD_GROUP("Gutters", "gutters_"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gutters_draw_breakpoints_gutter"), "set_draw_breakpoints_gutter", "is_drawing_breakpoints_gutter"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_executing_lines"), "set_draw_executing_lines_gutter", "is_drawing_executing_lines_gutter"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gutters_draw_bookmarks"), "set_draw_bookmarks_gutter", "is_drawing_bookmarks_gutter"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_line_numbers"), "set_draw_line_numbers", "is_draw_line_numbers_enabled"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "zero_pad_line_numbers"), "set_line_numbers_zero_padded", "is_line_numbers_zero_padded"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gutters_draw_executing_lines"), "set_draw_executing_lines_gutter", "is_drawing_executing_lines_gutter"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_fold_gutter"), "set_draw_fold_gutter", "is_drawing_fold_gutter"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gutters_draw_line_numbers"), "set_draw_line_numbers", "is_draw_line_numbers_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gutters_zero_pad_line_numbers"), "set_line_numbers_zero_padded", "is_line_numbers_zero_padded"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "line_folding"), "set_line_folding_enabled", "is_line_folding_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gutters_draw_fold_gutter"), "set_draw_fold_gutter", "is_drawing_fold_gutter"); ADD_GROUP("Delimiters", "delimiter_"); ADD_PROPERTY(PropertyInfo(Variant::PACKED_STRING_ARRAY, "delimiter_strings"), "set_string_delimiters", "get_string_delimiters"); @@ -2902,6 +2902,10 @@ CodeEdit::CodeEdit() { add_auto_brace_completion_pair("\"", "\""); add_auto_brace_completion_pair("\'", "\'"); + /* Delimiter traking */ + add_string_delimiter("\"", "\"", false); + add_string_delimiter("\'", "\'", false); + /* Text Direction */ set_layout_direction(LAYOUT_DIRECTION_LTR); set_text_direction(TEXT_DIRECTION_LTR); diff --git a/scene/gui/code_edit.h b/scene/gui/code_edit.h index efd778ffb3..72fdc6e787 100644 --- a/scene/gui/code_edit.h +++ b/scene/gui/code_edit.h @@ -125,7 +125,7 @@ private: void _update_gutter_indexes(); /* Line Folding */ - bool line_folding_enabled = true; + bool line_folding_enabled = false; /* Delimiters */ enum DelimiterType { diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index ad589d94d6..d0dee2b5e3 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -501,7 +501,6 @@ void fill_default_theme(Ref &theme, const Ref &default_font, const theme->set_color("caret_background_color", "CodeEdit", Color(0, 0, 0)); theme->set_color("brace_mismatch_color", "CodeEdit", Color(1, 0.2, 0.2)); theme->set_color("line_number_color", "CodeEdit", Color(0.67, 0.67, 0.67, 0.4)); - theme->set_color("safe_line_number_color", "CodeEdit", Color(0.67, 0.78, 0.67, 0.6)); theme->set_color("word_highlighted_color", "CodeEdit", Color(0.8, 0.9, 0.9, 0.15)); theme->set_color("line_length_guideline_color", "CodeEdit", Color(0.3, 0.5, 0.8, 0.1)); -- cgit v1.2.3