diff options
author | Paulb23 <p_batty@hotmail.co.uk> | 2021-06-30 11:58:13 +0100 |
---|---|---|
committer | Paulb23 <p_batty@hotmail.co.uk> | 2021-08-01 12:06:33 +0100 |
commit | d1a1ad127e03053a484fa71e1c36590d7e39ed95 (patch) | |
tree | f2b18d39b1bdec6bb044dd085073429875712d23 | |
parent | 12f00535555f8ac94a3da2a561f51357502e7a6d (diff) |
Move brace matching into CodeEdit
-rw-r--r-- | doc/classes/CodeEdit.xml | 3 | ||||
-rw-r--r-- | doc/classes/TextEdit.xml | 2 | ||||
-rw-r--r-- | editor/code_editor.cpp | 2 | ||||
-rw-r--r-- | scene/gui/code_edit.cpp | 13 | ||||
-rw-r--r-- | scene/gui/code_edit.h | 3 | ||||
-rw-r--r-- | scene/gui/text_edit.cpp | 6 | ||||
-rw-r--r-- | scene/gui/text_edit.h | 7 | ||||
-rw-r--r-- | scene/resources/default_theme/default_theme.cpp | 1 |
8 files changed, 25 insertions, 12 deletions
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 @@ <member name="auto_brace_completion_enabled" type="bool" setter="set_auto_brace_completion_enabled" getter="is_auto_brace_completion_enabled" default="false"> Sets whether brace pairs should be autocompleted. </member> + <member name="auto_brace_completion_highlight_matching" type="bool" setter="set_highlight_matching_braces_enabled" getter="is_highlight_matching_braces_enabled" default="false"> + Highlight mismatching brace pairs. + </member> <member name="auto_brace_completion_pairs" type="Dictionary" setter="set_auto_brace_completion_pairs" getter="get_auto_brace_completion_pairs" default="{"\"": "\"","'": "'","(": ")","[": "]","{": "}"}"> Sets the brace pairs to be autocompleted. </member> 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 @@ <theme_item name="background_color" type="Color" default="Color(0, 0, 0, 0)"> Sets the background [Color] of this [TextEdit]. </theme_item> - <theme_item name="brace_mismatch_color" type="Color" default="Color(1, 0.2, 0.2, 1)"> - </theme_item> <theme_item name="caret_background_color" type="Color" default="Color(0, 0, 0, 1)"> </theme_item> <theme_item name="caret_color" type="Color" default="Color(0.88, 0.88, 0.88, 1)"> 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<Texture2D> tab_icon; Ref<Texture2D> 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> &theme, const Ref<Font> &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); |