Move brace matching into CodeEdit
This commit is contained in:
parent
12f0053555
commit
d1a1ad127e
@ -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">
|
<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.
|
Sets whether brace pairs should be autocompleted.
|
||||||
</member>
|
</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="{"\"": "\"","'": "'","(": ")","[": "]","{": "}"}">
|
<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.
|
Sets the brace pairs to be autocompleted.
|
||||||
</member>
|
</member>
|
||||||
|
@ -798,8 +798,6 @@
|
|||||||
<theme_item name="background_color" type="Color" default="Color(0, 0, 0, 0)">
|
<theme_item name="background_color" type="Color" default="Color(0, 0, 0, 0)">
|
||||||
Sets the background [Color] of this [TextEdit].
|
Sets the background [Color] of this [TextEdit].
|
||||||
</theme_item>
|
</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 name="caret_background_color" type="Color" default="Color(0, 0, 0, 1)">
|
||||||
</theme_item>
|
</theme_item>
|
||||||
<theme_item name="caret_color" type="Color" default="Color(0.88, 0.88, 0.88, 1)">
|
<theme_item name="caret_color" type="Color" default="Color(0.88, 0.88, 0.88, 1)">
|
||||||
|
@ -1825,7 +1825,7 @@ CodeTextEditor::CodeTextEditor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
text_editor->set_draw_line_numbers(true);
|
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);
|
text_editor->set_auto_indent_enabled(true);
|
||||||
|
|
||||||
status_bar = memnew(HBoxContainer);
|
status_bar = memnew(HBoxContainer);
|
||||||
|
@ -937,6 +937,15 @@ bool CodeEdit::is_auto_brace_completion_enabled() const {
|
|||||||
return auto_brace_completion_enabled;
|
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) {
|
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_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");
|
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("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("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("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("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);
|
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_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_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");
|
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "auto_brace_completion_pairs"), "set_auto_brace_completion_pairs", "get_auto_brace_completion_pairs");
|
||||||
|
|
||||||
/* Signals */
|
/* Signals */
|
||||||
|
@ -259,6 +259,9 @@ public:
|
|||||||
void set_auto_brace_completion_enabled(bool p_enabled);
|
void set_auto_brace_completion_enabled(bool p_enabled);
|
||||||
bool is_auto_brace_completion_enabled() const;
|
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 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);
|
void set_auto_brace_completion_pairs(const Dictionary &p_auto_brace_completion_pairs);
|
||||||
Dictionary get_auto_brace_completion_pairs() const;
|
Dictionary get_auto_brace_completion_pairs() const;
|
||||||
|
@ -626,7 +626,7 @@ void TextEdit::_notification(int p_what) {
|
|||||||
bool brace_close_matching = false;
|
bool brace_close_matching = false;
|
||||||
bool brace_close_mismatch = 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()) {
|
if (cursor.column < text[cursor.line].length()) {
|
||||||
// Check for open.
|
// Check for open.
|
||||||
char32_t c = text[cursor.line][cursor.column];
|
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;
|
int char_pos = char_ofs + char_margin + ofs_x;
|
||||||
if (char_pos >= xmargin_beg) {
|
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) ||
|
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))) {
|
(cursor.column == glyphs[j].start && cursor.line == line && cursor_wrap_index == line_wrap_index && (brace_open_matching || brace_open_mismatch))) {
|
||||||
if (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.current_line_color = get_theme_color(SNAME("current_line_color"));
|
||||||
cache.line_length_guideline_color = get_theme_color(SNAME("line_length_guideline_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.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.word_highlighted_color = get_theme_color(SNAME("word_highlighted_color"));
|
||||||
cache.search_result_color = get_theme_color(SNAME("search_result_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"));
|
cache.search_result_border_color = get_theme_color(SNAME("search_result_border_color"));
|
||||||
|
@ -291,7 +291,6 @@ private:
|
|||||||
|
|
||||||
bool highlight_all_occurrences = false;
|
bool highlight_all_occurrences = false;
|
||||||
bool scroll_past_end_of_file_enabled = false;
|
bool scroll_past_end_of_file_enabled = false;
|
||||||
bool brace_matching_enabled = false;
|
|
||||||
bool highlight_current_line = false;
|
bool highlight_current_line = false;
|
||||||
|
|
||||||
String cut_copy_line;
|
String cut_copy_line;
|
||||||
@ -433,6 +432,8 @@ private:
|
|||||||
void _move_cursor_document_end(bool p_select);
|
void _move_cursor_document_end(bool p_select);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
bool highlight_matching_braces_enabled = false;
|
||||||
|
|
||||||
struct Cache {
|
struct Cache {
|
||||||
Ref<Texture2D> tab_icon;
|
Ref<Texture2D> tab_icon;
|
||||||
Ref<Texture2D> space_icon;
|
Ref<Texture2D> space_icon;
|
||||||
@ -628,10 +629,6 @@ public:
|
|||||||
scroll_past_end_of_file_enabled = p_enabled;
|
scroll_past_end_of_file_enabled = p_enabled;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
inline void set_brace_matching(bool p_enabled) {
|
|
||||||
brace_matching_enabled = p_enabled;
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void center_viewport_to_cursor();
|
void center_viewport_to_cursor();
|
||||||
|
|
||||||
|
@ -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("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_color", "TextEdit", control_font_color);
|
||||||
theme->set_color("caret_background_color", "TextEdit", Color(0, 0, 0));
|
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_color("word_highlighted_color", "TextEdit", Color(0.8, 0.9, 0.9, 0.15));
|
||||||
|
|
||||||
theme->set_constant("line_spacing", "TextEdit", 4 * scale);
|
theme->set_constant("line_spacing", "TextEdit", 4 * scale);
|
||||||
|
Loading…
Reference in New Issue
Block a user