summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
authorPaulb23 <p_batty@hotmail.co.uk>2021-06-30 11:58:13 +0100
committerPaulb23 <p_batty@hotmail.co.uk>2021-08-01 12:06:33 +0100
commitd1a1ad127e03053a484fa71e1c36590d7e39ed95 (patch)
treef2b18d39b1bdec6bb044dd085073429875712d23 /scene/gui
parent12f00535555f8ac94a3da2a561f51357502e7a6d (diff)
Move brace matching into CodeEdit
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/code_edit.cpp13
-rw-r--r--scene/gui/code_edit.h3
-rw-r--r--scene/gui/text_edit.cpp6
-rw-r--r--scene/gui/text_edit.h7
4 files changed, 21 insertions, 8 deletions
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();