diff options
Diffstat (limited to 'editor/code_editor.cpp')
-rw-r--r-- | editor/code_editor.cpp | 1639 |
1 files changed, 1034 insertions, 605 deletions
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index ede6dde239..212a46cb62 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -32,18 +32,16 @@ #include "core/input/input.h" #include "core/os/keyboard.h" -#include "core/string_builder.h" +#include "core/string/string_builder.h" #include "editor/editor_scale.h" -#include "editor_node.h" -#include "editor_settings.h" -#include "scene/gui/margin_container.h" -#include "scene/gui/separator.h" -#include "scene/resources/dynamic_font.h" +#include "editor/editor_settings.h" +#include "editor/plugins/script_editor_plugin.h" +#include "scene/resources/font.h" void GotoLineDialog::popup_find_line(CodeEdit *p_edit) { text_editor = p_edit; - line->set_text(itos(text_editor->cursor_get_line())); + line->set_text(itos(text_editor->get_caret_line())); line->select_all(); popup_centered(Size2(180, 80) * EDSCALE); line->grab_focus(); @@ -57,8 +55,9 @@ void GotoLineDialog::ok_pressed() { if (get_line() < 1 || get_line() > text_editor->get_line_count()) { return; } + text_editor->remove_secondary_carets(); text_editor->unfold_line(get_line() - 1); - text_editor->cursor_set_line(get_line() - 1); + text_editor->set_caret_line(get_line() - 1); hide(); } @@ -66,10 +65,10 @@ GotoLineDialog::GotoLineDialog() { set_title(TTR("Go to Line")); VBoxContainer *vbc = memnew(VBoxContainer); - vbc->set_anchor_and_margin(MARGIN_LEFT, Control::ANCHOR_BEGIN, 8 * EDSCALE); - vbc->set_anchor_and_margin(MARGIN_TOP, Control::ANCHOR_BEGIN, 8 * EDSCALE); - vbc->set_anchor_and_margin(MARGIN_RIGHT, Control::ANCHOR_END, -8 * EDSCALE); - vbc->set_anchor_and_margin(MARGIN_BOTTOM, Control::ANCHOR_END, -8 * EDSCALE); + vbc->set_anchor_and_offset(SIDE_LEFT, Control::ANCHOR_BEGIN, 8 * EDSCALE); + vbc->set_anchor_and_offset(SIDE_TOP, Control::ANCHOR_BEGIN, 8 * EDSCALE); + vbc->set_anchor_and_offset(SIDE_RIGHT, Control::ANCHOR_END, -8 * EDSCALE); + vbc->set_anchor_and_offset(SIDE_BOTTOM, Control::ANCHOR_END, -8 * EDSCALE); add_child(vbc); Label *l = memnew(Label); @@ -81,43 +80,54 @@ GotoLineDialog::GotoLineDialog() { register_text_enter(line); text_editor = nullptr; + line_label = nullptr; + set_hide_on_ok(false); } void FindReplaceBar::_notification(int p_what) { - if (p_what == NOTIFICATION_READY) { - find_prev->set_icon(get_theme_icon("MoveUp", "EditorIcons")); - find_next->set_icon(get_theme_icon("MoveDown", "EditorIcons")); - hide_button->set_normal_texture(get_theme_icon("Close", "EditorIcons")); - hide_button->set_hover_texture(get_theme_icon("Close", "EditorIcons")); - hide_button->set_pressed_texture(get_theme_icon("Close", "EditorIcons")); - hide_button->set_custom_minimum_size(hide_button->get_normal_texture()->get_size()); - } else if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - set_process_unhandled_input(is_visible_in_tree()); - } else if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { - find_prev->set_icon(get_theme_icon("MoveUp", "EditorIcons")); - find_next->set_icon(get_theme_icon("MoveDown", "EditorIcons")); - hide_button->set_normal_texture(get_theme_icon("Close", "EditorIcons")); - hide_button->set_hover_texture(get_theme_icon("Close", "EditorIcons")); - hide_button->set_pressed_texture(get_theme_icon("Close", "EditorIcons")); - hide_button->set_custom_minimum_size(hide_button->get_normal_texture()->get_size()); - } else if (p_what == NOTIFICATION_THEME_CHANGED) { - matches_label->add_theme_color_override("font_color", results_count > 0 ? get_theme_color("font_color", "Label") : get_theme_color("error_color", "Editor")); - } -} - -void FindReplaceBar::_unhandled_input(const Ref<InputEvent> &p_event) { + switch (p_what) { + case NOTIFICATION_READY: + case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { + find_prev->set_icon(get_theme_icon(SNAME("MoveUp"), SNAME("EditorIcons"))); + find_next->set_icon(get_theme_icon(SNAME("MoveDown"), SNAME("EditorIcons"))); + hide_button->set_normal_texture(get_theme_icon(SNAME("Close"), SNAME("EditorIcons"))); + hide_button->set_hover_texture(get_theme_icon(SNAME("Close"), SNAME("EditorIcons"))); + hide_button->set_pressed_texture(get_theme_icon(SNAME("Close"), SNAME("EditorIcons"))); + hide_button->set_custom_minimum_size(hide_button->get_normal_texture()->get_size()); + } break; + + case NOTIFICATION_VISIBILITY_CHANGED: { + set_process_unhandled_input(is_visible_in_tree()); + } break; + + case NOTIFICATION_THEME_CHANGED: { + matches_label->add_theme_color_override("font_color", results_count > 0 ? get_theme_color(SNAME("font_color"), SNAME("Label")) : get_theme_color(SNAME("error_color"), SNAME("Editor"))); + } break; + + case NOTIFICATION_PREDELETE: { + if (base_text_editor) { + base_text_editor->remove_find_replace_bar(); + base_text_editor = nullptr; + } + } break; + } +} + +void FindReplaceBar::unhandled_input(const Ref<InputEvent> &p_event) { + ERR_FAIL_COND(p_event.is_null()); + Ref<InputEventKey> k = p_event; if (!k.is_valid() || !k->is_pressed()) { return; } - Control *focus_owner = get_focus_owner(); - if (text_editor->has_focus() || (focus_owner && vbc_lineedit->is_a_parent_of(focus_owner))) { + Control *focus_owner = get_viewport()->gui_get_focus_owner(); + if (text_editor->has_focus() || (focus_owner && vbc_lineedit->is_ancestor_of(focus_owner))) { bool accepted = true; switch (k->get_keycode()) { - case KEY_ESCAPE: { + case Key::ESCAPE: { _hide_bar(); } break; default: { @@ -132,26 +142,25 @@ void FindReplaceBar::_unhandled_input(const Ref<InputEvent> &p_event) { } bool FindReplaceBar::_search(uint32_t p_flags, int p_from_line, int p_from_col) { - int line, col; String text = get_search_text(); + Point2i pos = text_editor->search(text, p_flags, p_from_line, p_from_col); - bool found = text_editor->search(text, p_flags, p_from_line, p_from_col, line, col); + if (pos.x != -1) { + if (!preserve_cursor && !is_selection_only()) { + text_editor->unfold_line(pos.y); + text_editor->set_caret_line(pos.y, false); + text_editor->set_caret_column(pos.x + text.length(), false); + text_editor->center_viewport_to_caret(0); + text_editor->select(pos.y, pos.x, pos.y, pos.x + text.length()); - if (found) { - if (!preserve_cursor) { - text_editor->unfold_line(line); - text_editor->cursor_set_line(line, false); - text_editor->cursor_set_column(col + text.length(), false); - text_editor->center_viewport_to_cursor(); - text_editor->select(line, col, line, col + text.length()); + line_col_changed_for_result = true; } text_editor->set_search_text(text); text_editor->set_search_flags(p_flags); - text_editor->set_current_search_result(line, col); - result_line = line; - result_col = col; + result_line = pos.y; + result_col = pos.x; _update_results_count(); } else { @@ -160,78 +169,84 @@ bool FindReplaceBar::_search(uint32_t p_flags, int p_from_line, int p_from_col) result_col = -1; text_editor->set_search_text(""); text_editor->set_search_flags(p_flags); - text_editor->set_current_search_result(line, col); } _update_matches_label(); - return found; + return pos.x != -1; } void FindReplaceBar::_replace() { - bool selection_enabled = text_editor->is_selection_active(); + bool selection_enabled = text_editor->has_selection(0); Point2i selection_begin, selection_end; if (selection_enabled) { - selection_begin = Point2i(text_editor->get_selection_from_line(), text_editor->get_selection_from_column()); - selection_end = Point2i(text_editor->get_selection_to_line(), text_editor->get_selection_to_column()); + selection_begin = Point2i(text_editor->get_selection_from_line(0), text_editor->get_selection_from_column(0)); + selection_end = Point2i(text_editor->get_selection_to_line(0), text_editor->get_selection_to_column(0)); } - String replace_text = get_replace_text(); + String repl_text = get_replace_text(); int search_text_len = get_search_text().length(); text_editor->begin_complex_operation(); if (selection_enabled && is_selection_only()) { // To restrict search_current() to selected region - text_editor->cursor_set_line(selection_begin.width); - text_editor->cursor_set_column(selection_begin.height); + text_editor->set_caret_line(selection_begin.width, false, true, 0, 0); + text_editor->set_caret_column(selection_begin.height, true, 0); } if (search_current()) { text_editor->unfold_line(result_line); - text_editor->select(result_line, result_col, result_line, result_col + search_text_len); + text_editor->select(result_line, result_col, result_line, result_col + search_text_len, 0); if (selection_enabled && is_selection_only()) { Point2i match_from(result_line, result_col); Point2i match_to(result_line, result_col + search_text_len); if (!(match_from < selection_begin || match_to > selection_end)) { - text_editor->insert_text_at_cursor(replace_text); + text_editor->insert_text_at_caret(repl_text, 0); if (match_to.x == selection_end.x) { // Adjust selection bounds if necessary - selection_end.y += replace_text.length() - search_text_len; + selection_end.y += repl_text.length() - search_text_len; } } } else { - text_editor->insert_text_at_cursor(replace_text); + text_editor->insert_text_at_caret(repl_text, 0); } } text_editor->end_complex_operation(); results_count = -1; + results_count_to_current = -1; + needs_to_count_results = true; if (selection_enabled && is_selection_only()) { // Reselect in order to keep 'Replace' restricted to selection - text_editor->select(selection_begin.x, selection_begin.y, selection_end.x, selection_end.y); + text_editor->select(selection_begin.x, selection_begin.y, selection_end.x, selection_end.y, 0); } else { - text_editor->deselect(); + text_editor->deselect(0); } } void FindReplaceBar::_replace_all() { text_editor->disconnect("text_changed", callable_mp(this, &FindReplaceBar::_editor_text_changed)); // Line as x so it gets priority in comparison, column as y. - Point2i orig_cursor(text_editor->cursor_get_line(), text_editor->cursor_get_column()); + Point2i orig_cursor(text_editor->get_caret_line(0), text_editor->get_caret_column(0)); Point2i prev_match = Point2(-1, -1); - bool selection_enabled = text_editor->is_selection_active(); + bool selection_enabled = text_editor->has_selection(0); + if (!is_selection_only()) { + text_editor->deselect(); + selection_enabled = false; + } else { + result_line = -1; + result_col = -1; + } + Point2i selection_begin, selection_end; if (selection_enabled) { - selection_begin = Point2i(text_editor->get_selection_from_line(), text_editor->get_selection_from_column()); - selection_end = Point2i(text_editor->get_selection_to_line(), text_editor->get_selection_to_column()); + selection_begin = Point2i(text_editor->get_selection_from_line(0), text_editor->get_selection_from_column(0)); + selection_end = Point2i(text_editor->get_selection_to_line(0), text_editor->get_selection_to_column(0)); } int vsval = text_editor->get_v_scroll(); - text_editor->cursor_set_line(0); - text_editor->cursor_set_column(0); - - String replace_text = get_replace_text(); + String repl_text = get_replace_text(); int search_text_len = get_search_text().length(); int rc = 0; @@ -241,9 +256,13 @@ void FindReplaceBar::_replace_all() { text_editor->begin_complex_operation(); if (selection_enabled && is_selection_only()) { - text_editor->cursor_set_line(selection_begin.width); - text_editor->cursor_set_column(selection_begin.height); + text_editor->set_caret_line(selection_begin.width, false, true, 0, 0); + text_editor->set_caret_column(selection_begin.height, true, 0); + } else { + text_editor->set_caret_line(0, false, true, 0, 0); + text_editor->set_caret_column(0, true, 0); } + if (search_current()) { do { // replace area @@ -254,25 +273,25 @@ void FindReplaceBar::_replace_all() { break; // Done. } - prev_match = Point2i(result_line, result_col + replace_text.length()); + prev_match = Point2i(result_line, result_col + repl_text.length()); text_editor->unfold_line(result_line); - text_editor->select(result_line, result_col, result_line, match_to.y); + text_editor->select(result_line, result_col, result_line, match_to.y, 0); - if (selection_enabled && is_selection_only()) { + if (selection_enabled) { if (match_from < selection_begin || match_to > selection_end) { break; // Done. } // Replace but adjust selection bounds. - text_editor->insert_text_at_cursor(replace_text); + text_editor->insert_text_at_caret(repl_text, 0); if (match_to.x == selection_end.x) { - selection_end.y += replace_text.length() - search_text_len; + selection_end.y += repl_text.length() - search_text_len; } } else { // Just replace. - text_editor->insert_text_at_cursor(replace_text); + text_editor->insert_text_at_caret(repl_text, 0); } rc++; @@ -284,88 +303,123 @@ void FindReplaceBar::_replace_all() { replace_all_mode = false; // Restore editor state (selection, cursor, scroll). - text_editor->cursor_set_line(orig_cursor.x); - text_editor->cursor_set_column(orig_cursor.y); + text_editor->set_caret_line(orig_cursor.x, false, true, 0, 0); + text_editor->set_caret_column(orig_cursor.y, true, 0); - if (selection_enabled && is_selection_only()) { + if (selection_enabled) { // Reselect. - text_editor->select(selection_begin.x, selection_begin.y, selection_end.x, selection_end.y); - } else { - text_editor->deselect(); + text_editor->select(selection_begin.x, selection_begin.y, selection_end.x, selection_end.y, 0); } text_editor->set_v_scroll(vsval); - matches_label->add_theme_color_override("font_color", rc > 0 ? get_theme_color("font_color", "Label") : get_theme_color("error_color", "Editor")); + matches_label->add_theme_color_override("font_color", rc > 0 ? get_theme_color(SNAME("font_color"), SNAME("Label")) : get_theme_color(SNAME("error_color"), SNAME("Editor"))); matches_label->set_text(vformat(TTR("%d replaced."), rc)); - text_editor->call_deferred("connect", "text_changed", Callable(this, "_editor_text_changed")); + text_editor->call_deferred(SNAME("connect"), "text_changed", callable_mp(this, &FindReplaceBar::_editor_text_changed)); results_count = -1; + results_count_to_current = -1; + needs_to_count_results = true; } -void FindReplaceBar::_get_search_from(int &r_line, int &r_col) { - r_line = text_editor->cursor_get_line(); - r_col = text_editor->cursor_get_column(); +void FindReplaceBar::_get_search_from(int &r_line, int &r_col, bool p_is_searching_next) { + if (!text_editor->has_selection(0) || is_selection_only()) { + r_line = text_editor->get_caret_line(0); + r_col = text_editor->get_caret_column(0); - if (text_editor->is_selection_active() && is_selection_only()) { + if (!p_is_searching_next && r_line == result_line && r_col >= result_col && r_col <= result_col + get_search_text().length()) { + r_col = result_col; + } return; } - if (r_line == result_line && r_col >= result_col && r_col <= result_col + get_search_text().length()) { - r_col = result_col; + if (p_is_searching_next) { + r_line = text_editor->get_selection_to_line(); + r_col = text_editor->get_selection_to_column(); + } else { + r_line = text_editor->get_selection_from_line(); + r_col = text_editor->get_selection_from_column(); } } void FindReplaceBar::_update_results_count() { - if (results_count != -1) { + if (!needs_to_count_results && (result_line != -1) && results_count_to_current > 0) { + results_count_to_current += (flags & TextEdit::SEARCH_BACKWARDS) ? -1 : 1; + + if (results_count_to_current > results_count) { + results_count_to_current = results_count_to_current - results_count; + } else if (results_count_to_current <= 0) { + results_count_to_current = results_count; + } + return; } - results_count = 0; - String searched = get_search_text(); - if (searched.empty()) { + if (searched.is_empty()) { return; } - String full_text = text_editor->get_text(); + needs_to_count_results = false; - int from_pos = 0; + results_count = 0; - while (true) { - int pos = is_case_sensitive() ? full_text.find(searched, from_pos) : full_text.findn(searched, from_pos); - if (pos == -1) { - break; - } + for (int i = 0; i < text_editor->get_line_count(); i++) { + String line_text = text_editor->get_line(i); - int pos_subsequent = pos + searched.length(); - if (is_whole_words()) { - from_pos = pos + 1; // Making sure we won't hit the same match next time, if we get out via a continue. - if (pos > 0 && !(is_symbol(full_text[pos - 1]) || full_text[pos - 1] == '\n')) { - continue; + int col_pos = 0; + + while (true) { + col_pos = is_case_sensitive() ? line_text.find(searched, col_pos) : line_text.findn(searched, col_pos); + + if (col_pos == -1) { + break; } - if (pos_subsequent < full_text.length() && !(is_symbol(full_text[pos_subsequent]) || full_text[pos_subsequent] == '\n')) { - continue; + + if (is_whole_words()) { + if (col_pos > 0 && !is_symbol(line_text[col_pos - 1])) { + break; + } + if (col_pos + line_text.length() < line_text.length() && !is_symbol(line_text[col_pos + searched.length()])) { + break; + } } - } - results_count++; - from_pos = pos_subsequent; + results_count++; + + if (i == result_line) { + if (col_pos == result_col) { + results_count_to_current = results_count; + } else if (col_pos < result_col && col_pos + searched.length() > result_col) { + col_pos = result_col; + results_count_to_current = results_count; + } + } + + col_pos += searched.length(); + } } } void FindReplaceBar::_update_matches_label() { - if (search_text->get_text().empty() || results_count == -1) { + if (search_text->get_text().is_empty() || results_count == -1) { matches_label->hide(); } else { matches_label->show(); - matches_label->add_theme_color_override("font_color", results_count > 0 ? get_theme_color("font_color", "Label") : get_theme_color("error_color", "Editor")); - matches_label->set_text(vformat(results_count == 1 ? TTR("%d match.") : TTR("%d matches."), results_count)); + matches_label->add_theme_color_override("font_color", results_count > 0 ? get_theme_color(SNAME("font_color"), SNAME("Label")) : get_theme_color(SNAME("error_color"), SNAME("Editor"))); + + if (results_count == 0) { + matches_label->set_text("No match"); + } else if (results_count_to_current == -1) { + matches_label->set_text(vformat(TTRN("%d match", "%d matches", results_count), results_count)); + } else { + matches_label->set_text(vformat(TTRN("%d of %d match", "%d of %d matches", results_count), results_count_to_current, results_count)); + } } } bool FindReplaceBar::search_current() { - uint32_t flags = 0; + flags = 0; if (is_whole_words()) { flags |= TextEdit::SEARCH_WHOLE_WORDS; @@ -381,11 +435,15 @@ bool FindReplaceBar::search_current() { } bool FindReplaceBar::search_prev() { + if (is_selection_only() && !replace_all_mode) { + return false; + } + if (!is_visible()) { popup_search(true); } - uint32_t flags = 0; + flags = 0; String text = get_search_text(); if (is_whole_words()) { @@ -399,9 +457,6 @@ bool FindReplaceBar::search_prev() { int line, col; _get_search_from(line, col); - if (text_editor->is_selection_active()) { - col--; // Skip currently selected word. - } col -= text.length(); if (col < 0) { @@ -416,17 +471,15 @@ bool FindReplaceBar::search_prev() { } bool FindReplaceBar::search_next() { + if (is_selection_only() && !replace_all_mode) { + return false; + } + if (!is_visible()) { popup_search(true); } - uint32_t flags = 0; - String text; - if (replace_all_mode) { - text = get_replace_text(); - } else { - text = get_search_text(); - } + flags = 0; if (is_whole_words()) { flags |= TextEdit::SEARCH_WHOLE_WORDS; @@ -436,18 +489,7 @@ bool FindReplaceBar::search_next() { } int line, col; - _get_search_from(line, col); - - if (line == result_line && col == result_col) { - col += text.length(); - if (col > text_editor->get_line(line).length()) { - line += 1; - if (line >= text_editor->get_line_count()) { - line = 0; - } - col = 0; - } - } + _get_search_from(line, col, true); return _search(flags, line, col); } @@ -471,26 +513,30 @@ void FindReplaceBar::_show_search(bool p_focus_replace, bool p_show_only) { if (p_focus_replace) { search_text->deselect(); - replace_text->call_deferred("grab_focus"); + replace_text->call_deferred(SNAME("grab_focus")); } else { replace_text->deselect(); - search_text->call_deferred("grab_focus"); + search_text->call_deferred(SNAME("grab_focus")); } - if (text_editor->is_selection_active() && !selection_only->is_pressed()) { - search_text->set_text(text_editor->get_selection_text()); + if (text_editor->has_selection(0) && !is_selection_only()) { + search_text->set_text(text_editor->get_selected_text(0)); + result_line = text_editor->get_selection_from_line(); + result_col = text_editor->get_selection_from_column(); } - if (!get_search_text().empty()) { + if (!get_search_text().is_empty()) { if (p_focus_replace) { replace_text->select_all(); - replace_text->set_cursor_position(replace_text->get_text().length()); + replace_text->set_caret_column(replace_text->get_text().length()); } else { search_text->select_all(); - search_text->set_cursor_position(search_text->get_text().length()); + search_text->set_caret_column(search_text->get_text().length()); } results_count = -1; + results_count_to_current = -1; + needs_to_count_results = true; _update_results_count(); _update_matches_label(); } @@ -500,6 +546,7 @@ void FindReplaceBar::popup_search(bool p_show_only) { replace_text->hide(); hbc_button_replace->hide(); hbc_option_replace->hide(); + selection_only->set_pressed(false); _show_search(false, p_show_only); } @@ -511,18 +558,22 @@ void FindReplaceBar::popup_replace() { hbc_option_replace->show(); } - selection_only->set_pressed((text_editor->is_selection_active() && text_editor->get_selection_from_line() < text_editor->get_selection_to_line())); + selection_only->set_pressed((text_editor->has_selection(0) && text_editor->get_selection_from_line(0) < text_editor->get_selection_to_line(0))); - _show_search(is_visible() || text_editor->is_selection_active()); + _show_search(is_visible() || text_editor->has_selection(0)); } void FindReplaceBar::_search_options_changed(bool p_pressed) { results_count = -1; + results_count_to_current = -1; + needs_to_count_results = true; search_current(); } void FindReplaceBar::_editor_text_changed() { results_count = -1; + results_count_to_current = -1; + needs_to_count_results = true; if (is_visible_in_tree()) { preserve_cursor = true; search_current(); @@ -532,22 +583,24 @@ void FindReplaceBar::_editor_text_changed() { void FindReplaceBar::_search_text_changed(const String &p_text) { results_count = -1; + results_count_to_current = -1; + needs_to_count_results = true; search_current(); } -void FindReplaceBar::_search_text_entered(const String &p_text) { - if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { +void FindReplaceBar::_search_text_submitted(const String &p_text) { + if (Input::get_singleton()->is_key_pressed(Key::SHIFT)) { search_prev(); } else { search_next(); } } -void FindReplaceBar::_replace_text_entered(const String &p_text) { - if (selection_only->is_pressed() && text_editor->is_selection_active()) { +void FindReplaceBar::_replace_text_submitted(const String &p_text) { + if (selection_only->is_pressed() && text_editor->has_selection(0)) { _replace_all(); _hide_bar(); - } else if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { + } else if (Input::get_singleton()->is_key_pressed(Key::SHIFT)) { _replace(); search_prev(); } else { @@ -576,18 +629,37 @@ bool FindReplaceBar::is_selection_only() const { } void FindReplaceBar::set_error(const String &p_label) { - emit_signal("error", p_label); + emit_signal(SNAME("error"), p_label); } -void FindReplaceBar::set_text_edit(CodeEdit *p_text_edit) { +void FindReplaceBar::set_text_edit(CodeTextEditor *p_text_editor) { + if (p_text_editor == base_text_editor) { + return; + } + + if (base_text_editor) { + base_text_editor->remove_find_replace_bar(); + base_text_editor = nullptr; + text_editor->disconnect("text_changed", callable_mp(this, &FindReplaceBar::_editor_text_changed)); + text_editor = nullptr; + } + + if (!p_text_editor) { + return; + } + results_count = -1; - text_editor = p_text_edit; + results_count_to_current = -1; + needs_to_count_results = true; + base_text_editor = p_text_editor; + text_editor = base_text_editor->get_text_editor(); text_editor->connect("text_changed", callable_mp(this, &FindReplaceBar::_editor_text_changed)); + + _update_results_count(); + _update_matches_label(); } void FindReplaceBar::_bind_methods() { - ClassDB::bind_method("_unhandled_input", &FindReplaceBar::_unhandled_input); - ClassDB::bind_method("_search_current", &FindReplaceBar::search_current); ADD_SIGNAL(MethodInfo("search")); @@ -595,13 +667,9 @@ void FindReplaceBar::_bind_methods() { } FindReplaceBar::FindReplaceBar() { - results_count = -1; - replace_all_mode = false; - preserve_cursor = false; - vbc_lineedit = memnew(VBoxContainer); add_child(vbc_lineedit); - vbc_lineedit->set_alignment(ALIGN_CENTER); + vbc_lineedit->set_alignment(BoxContainer::ALIGNMENT_CENTER); vbc_lineedit->set_h_size_flags(SIZE_EXPAND_FILL); VBoxContainer *vbc_button = memnew(VBoxContainer); add_child(vbc_button); @@ -610,10 +678,10 @@ FindReplaceBar::FindReplaceBar() { HBoxContainer *hbc_button_search = memnew(HBoxContainer); vbc_button->add_child(hbc_button_search); - hbc_button_search->set_alignment(ALIGN_END); + hbc_button_search->set_alignment(BoxContainer::ALIGNMENT_END); hbc_button_replace = memnew(HBoxContainer); vbc_button->add_child(hbc_button_replace); - hbc_button_replace->set_alignment(ALIGN_END); + hbc_button_replace->set_alignment(BoxContainer::ALIGNMENT_END); HBoxContainer *hbc_option_search = memnew(HBoxContainer); vbc_option->add_child(hbc_option_search); @@ -625,7 +693,7 @@ FindReplaceBar::FindReplaceBar() { vbc_lineedit->add_child(search_text); search_text->set_custom_minimum_size(Size2(100 * EDSCALE, 0)); search_text->connect("text_changed", callable_mp(this, &FindReplaceBar::_search_text_changed)); - search_text->connect("text_entered", callable_mp(this, &FindReplaceBar::_search_text_entered)); + search_text->connect("text_submitted", callable_mp(this, &FindReplaceBar::_search_text_submitted)); matches_label = memnew(Label); hbc_button_search->add_child(matches_label); @@ -659,7 +727,7 @@ FindReplaceBar::FindReplaceBar() { replace_text = memnew(LineEdit); vbc_lineedit->add_child(replace_text); replace_text->set_custom_minimum_size(Size2(100 * EDSCALE, 0)); - replace_text->connect("text_entered", callable_mp(this, &FindReplaceBar::_replace_text_entered)); + replace_text->connect("text_submitted", callable_mp(this, &FindReplaceBar::_replace_text_submitted)); replace = memnew(Button); hbc_button_replace->add_child(replace); @@ -688,9 +756,31 @@ FindReplaceBar::FindReplaceBar() { // This function should be used to handle shortcuts that could otherwise // be handled too late if they weren't handled here. -void CodeTextEditor::_input(const Ref<InputEvent> &event) { +void CodeTextEditor::input(const Ref<InputEvent> &event) { + ERR_FAIL_COND(event.is_null()); + const Ref<InputEventKey> key_event = event; - if (!key_event.is_valid() || !key_event->is_pressed() || !text_editor->has_focus()) { + + if (!key_event.is_valid()) { + return; + } + if (!key_event->is_pressed()) { + return; + } + + if (!text_editor->has_focus()) { + if ((find_replace_bar != nullptr && find_replace_bar->is_visible()) && (find_replace_bar->has_focus() || find_replace_bar->is_ancestor_of(get_viewport()->gui_get_focus_owner()))) { + if (ED_IS_SHORTCUT("script_text_editor/find_next", key_event)) { + find_replace_bar->search_next(); + accept_event(); + return; + } + if (ED_IS_SHORTCUT("script_text_editor/find_previous", key_event)) { + find_replace_bar->search_prev(); + accept_event(); + return; + } + } return; } @@ -709,8 +799,8 @@ void CodeTextEditor::_input(const Ref<InputEvent> &event) { accept_event(); return; } - if (ED_IS_SHORTCUT("script_text_editor/clone_down", key_event)) { - clone_lines_down(); + if (ED_IS_SHORTCUT("script_text_editor/duplicate_selection", key_event)) { + duplicate_selection(); accept_event(); return; } @@ -720,10 +810,10 @@ void CodeTextEditor::_text_editor_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid()) { - if (mb->is_pressed() && mb->get_command()) { - if (mb->get_button_index() == BUTTON_WHEEL_UP) { + if (mb->is_pressed() && mb->is_command_or_control_pressed()) { + if (mb->get_button_index() == MouseButton::WHEEL_UP) { _zoom_in(); - } else if (mb->get_button_index() == BUTTON_WHEEL_DOWN) { + } else if (mb->get_button_index() == MouseButton::WHEEL_DOWN) { _zoom_out(); } } @@ -731,17 +821,10 @@ void CodeTextEditor::_text_editor_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMagnifyGesture> magnify_gesture = p_event; if (magnify_gesture.is_valid()) { - Ref<DynamicFont> font = text_editor->get_theme_font("font"); - - if (font.is_valid()) { - if (font->get_size() != (int)font_size) { - font_size = font->get_size(); - } - - font_size *= powf(magnify_gesture->get_factor(), 0.25); + font_size = text_editor->get_theme_font_size(SNAME("font_size")); + font_size *= powf(magnify_gesture->get_factor(), 0.25); - _add_font_size((int)font_size - font->get_size()); - } + _add_font_size((int)font_size - text_editor->get_theme_font_size(SNAME("font_size"))); return; } @@ -751,12 +834,15 @@ void CodeTextEditor::_text_editor_gui_input(const Ref<InputEvent> &p_event) { if (k->is_pressed()) { if (ED_IS_SHORTCUT("script_editor/zoom_in", p_event)) { _zoom_in(); + accept_event(); } if (ED_IS_SHORTCUT("script_editor/zoom_out", p_event)) { _zoom_out(); + accept_event(); } if (ED_IS_SHORTCUT("script_editor/reset_zoom", p_event)) { _reset_zoom(); + accept_event(); } } } @@ -779,19 +865,15 @@ void CodeTextEditor::_zoom_changed() { } void CodeTextEditor::_reset_zoom() { - Ref<DynamicFont> font = text_editor->get_theme_font("font"); // Reset source font size to default. - - if (font.is_valid()) { - EditorSettings::get_singleton()->set("interface/editor/code_font_size", 14); - font->set_size(14); - } + EditorSettings::get_singleton()->set("interface/editor/code_font_size", 14); + text_editor->add_theme_font_size_override("font_size", 14 * EDSCALE); } void CodeTextEditor::_line_col_changed() { - String line = text_editor->get_line(text_editor->cursor_get_line()); + String line = text_editor->get_line(text_editor->get_caret_line()); int positional_column = 0; - for (int i = 0; i < text_editor->cursor_get_column(); i++) { + for (int i = 0; i < text_editor->get_caret_column(); i++) { if (line[i] == '\t') { positional_column += text_editor->get_indent_size(); //tab size } else { @@ -800,13 +882,19 @@ void CodeTextEditor::_line_col_changed() { } StringBuilder sb; - sb.append("("); - sb.append(itos(text_editor->cursor_get_line() + 1).lpad(3)); - sb.append(","); + sb.append(itos(text_editor->get_caret_line() + 1).lpad(4)); + sb.append(" : "); sb.append(itos(positional_column + 1).lpad(3)); - sb.append(")"); line_and_col_txt->set_text(sb.as_string()); + + if (find_replace_bar) { + if (!find_replace_bar->line_col_changed_for_result) { + find_replace_bar->needs_to_count_results = true; + } + + find_replace_bar->line_col_changed_for_result = false; + } } void CodeTextEditor::_text_changed() { @@ -815,18 +903,22 @@ void CodeTextEditor::_text_changed() { } idle->start(); + + if (find_replace_bar) { + find_replace_bar->needs_to_count_results = true; + } } void CodeTextEditor::_code_complete_timer_timeout() { if (!is_visible_in_tree()) { return; } - text_editor->query_code_comple(); + text_editor->request_code_completion(); } void CodeTextEditor::_complete_request() { - List<ScriptCodeCompletionOption> entries; - String ctext = text_editor->get_text_for_completion(); + List<ScriptLanguage::CodeCompletionOption> entries; + String ctext = text_editor->get_text_for_code_completion(); _code_complete_script(ctext, &entries); bool forced = false; if (code_complete_func) { @@ -836,58 +928,57 @@ void CodeTextEditor::_complete_request() { return; } - for (List<ScriptCodeCompletionOption>::Element *E = entries.front(); E; E = E->next()) { - ScriptCodeCompletionOption *e = &E->get(); - e->icon = _get_completion_icon(*e); - e->font_color = completion_font_color; - if (e->insert_text.begins_with("\"") || e->insert_text.begins_with("\'")) { - e->font_color = completion_string_color; - } else if (e->insert_text.begins_with("#") || e->insert_text.begins_with("//")) { - e->font_color = completion_comment_color; + for (const ScriptLanguage::CodeCompletionOption &e : entries) { + Color font_color = completion_font_color; + if (e.insert_text.begins_with("\"") || e.insert_text.begins_with("\'")) { + font_color = completion_string_color; + } else if (e.insert_text.begins_with("#") || e.insert_text.begins_with("//")) { + font_color = completion_comment_color; } + text_editor->add_code_completion_option((CodeEdit::CodeCompletionKind)e.kind, e.display, e.insert_text, font_color, _get_completion_icon(e), e.default_value); } - text_editor->code_complete(entries, forced); + text_editor->update_code_completion_options(forced); } -Ref<Texture2D> CodeTextEditor::_get_completion_icon(const ScriptCodeCompletionOption &p_option) { +Ref<Texture2D> CodeTextEditor::_get_completion_icon(const ScriptLanguage::CodeCompletionOption &p_option) { Ref<Texture2D> tex; switch (p_option.kind) { - case ScriptCodeCompletionOption::KIND_CLASS: { - if (has_theme_icon(p_option.display, "EditorIcons")) { - tex = get_theme_icon(p_option.display, "EditorIcons"); + case ScriptLanguage::CODE_COMPLETION_KIND_CLASS: { + if (has_theme_icon(p_option.display, SNAME("EditorIcons"))) { + tex = get_theme_icon(p_option.display, SNAME("EditorIcons")); } else { - tex = get_theme_icon("Object", "EditorIcons"); + tex = get_theme_icon(SNAME("Object"), SNAME("EditorIcons")); } } break; - case ScriptCodeCompletionOption::KIND_ENUM: - tex = get_theme_icon("Enum", "EditorIcons"); + case ScriptLanguage::CODE_COMPLETION_KIND_ENUM: + tex = get_theme_icon(SNAME("Enum"), SNAME("EditorIcons")); break; - case ScriptCodeCompletionOption::KIND_FILE_PATH: - tex = get_theme_icon("File", "EditorIcons"); + case ScriptLanguage::CODE_COMPLETION_KIND_FILE_PATH: + tex = get_theme_icon(SNAME("File"), SNAME("EditorIcons")); break; - case ScriptCodeCompletionOption::KIND_NODE_PATH: - tex = get_theme_icon("NodePath", "EditorIcons"); + case ScriptLanguage::CODE_COMPLETION_KIND_NODE_PATH: + tex = get_theme_icon(SNAME("NodePath"), SNAME("EditorIcons")); break; - case ScriptCodeCompletionOption::KIND_VARIABLE: - tex = get_theme_icon("Variant", "EditorIcons"); + case ScriptLanguage::CODE_COMPLETION_KIND_VARIABLE: + tex = get_theme_icon(SNAME("Variant"), SNAME("EditorIcons")); break; - case ScriptCodeCompletionOption::KIND_CONSTANT: - tex = get_theme_icon("MemberConstant", "EditorIcons"); + case ScriptLanguage::CODE_COMPLETION_KIND_CONSTANT: + tex = get_theme_icon(SNAME("MemberConstant"), SNAME("EditorIcons")); break; - case ScriptCodeCompletionOption::KIND_MEMBER: - tex = get_theme_icon("MemberProperty", "EditorIcons"); + case ScriptLanguage::CODE_COMPLETION_KIND_MEMBER: + tex = get_theme_icon(SNAME("MemberProperty"), SNAME("EditorIcons")); break; - case ScriptCodeCompletionOption::KIND_SIGNAL: - tex = get_theme_icon("MemberSignal", "EditorIcons"); + case ScriptLanguage::CODE_COMPLETION_KIND_SIGNAL: + tex = get_theme_icon(SNAME("MemberSignal"), SNAME("EditorIcons")); break; - case ScriptCodeCompletionOption::KIND_FUNCTION: - tex = get_theme_icon("MemberMethod", "EditorIcons"); + case ScriptLanguage::CODE_COMPLETION_KIND_FUNCTION: + tex = get_theme_icon(SNAME("MemberMethod"), SNAME("EditorIcons")); break; - case ScriptCodeCompletionOption::KIND_PLAIN_TEXT: - tex = get_theme_icon("CubeMesh", "EditorIcons"); + case ScriptLanguage::CODE_COMPLETION_KIND_PLAIN_TEXT: + tex = get_theme_icon(SNAME("BoxMesh"), SNAME("EditorIcons")); break; default: - tex = get_theme_icon("String", "EditorIcons"); + tex = get_theme_icon(SNAME("String"), SNAME("EditorIcons")); break; } return tex; @@ -900,52 +991,92 @@ void CodeTextEditor::_font_resize_timeout() { } bool CodeTextEditor::_add_font_size(int p_delta) { - Ref<DynamicFont> font = text_editor->get_theme_font("font"); + int old_size = text_editor->get_theme_font_size(SNAME("font_size")); + int new_size = CLAMP(old_size + p_delta, 8 * EDSCALE, 96 * EDSCALE); - if (font.is_valid()) { - int new_size = CLAMP(font->get_size() + p_delta, 8 * EDSCALE, 96 * EDSCALE); + if (new_size != old_size) { + EditorSettings::get_singleton()->set("interface/editor/code_font_size", new_size / EDSCALE); + text_editor->add_theme_font_size_override("font_size", new_size); + } - if (new_size != font->get_size()) { - EditorSettings::get_singleton()->set("interface/editor/code_font_size", new_size / EDSCALE); - font->set_size(new_size); - } + return true; +} - return true; +void CodeTextEditor::update_editor_settings() { + // Theme: Highlighting + completion_font_color = EDITOR_GET("text_editor/theme/highlighting/completion_font_color"); + completion_string_color = EDITOR_GET("text_editor/theme/highlighting/string_color"); + completion_comment_color = EDITOR_GET("text_editor/theme/highlighting/comment_color"); + + // Appearance: Caret + text_editor->set_caret_type((TextEdit::CaretType)EDITOR_GET("text_editor/appearance/caret/type").operator int()); + text_editor->set_caret_blink_enabled(EDITOR_GET("text_editor/appearance/caret/caret_blink")); + text_editor->set_caret_blink_interval(EDITOR_GET("text_editor/appearance/caret/caret_blink_interval")); + text_editor->set_highlight_current_line(EDITOR_GET("text_editor/appearance/caret/highlight_current_line")); + text_editor->set_highlight_all_occurrences(EDITOR_GET("text_editor/appearance/caret/highlight_all_occurrences")); + + // Appearance: Gutters + text_editor->set_draw_line_numbers(EDITOR_GET("text_editor/appearance/gutters/show_line_numbers")); + text_editor->set_line_numbers_zero_padded(EDITOR_GET("text_editor/appearance/gutters/line_numbers_zero_padded")); + text_editor->set_draw_bookmarks_gutter(EDITOR_GET("text_editor/appearance/gutters/show_bookmark_gutter")); + + // Appearance: Minimap + text_editor->set_draw_minimap(EDITOR_GET("text_editor/appearance/minimap/show_minimap")); + text_editor->set_minimap_width((int)EDITOR_GET("text_editor/appearance/minimap/minimap_width") * EDSCALE); + + // Appearance: Lines + text_editor->set_line_folding_enabled(EDITOR_GET("text_editor/appearance/lines/code_folding")); + text_editor->set_draw_fold_gutter(EDITOR_GET("text_editor/appearance/lines/code_folding")); + text_editor->set_line_wrapping_mode((TextEdit::LineWrappingMode)EDITOR_GET("text_editor/appearance/lines/word_wrap").operator int()); + + // Appearance: Whitespace + text_editor->set_draw_tabs(EDITOR_GET("text_editor/appearance/whitespace/draw_tabs")); + text_editor->set_draw_spaces(EDITOR_GET("text_editor/appearance/whitespace/draw_spaces")); + + // Behavior: Navigation + text_editor->set_scroll_past_end_of_file_enabled(EDITOR_GET("text_editor/behavior/navigation/scroll_past_end_of_file")); + text_editor->set_smooth_scroll_enabled(EDITOR_GET("text_editor/behavior/navigation/smooth_scrolling")); + text_editor->set_v_scroll_speed(EDITOR_GET("text_editor/behavior/navigation/v_scroll_speed")); + text_editor->set_drag_and_drop_selection_enabled(EDITOR_GET("text_editor/behavior/navigation/drag_and_drop_selection")); + + // Behavior: indent + text_editor->set_indent_using_spaces(EDITOR_GET("text_editor/behavior/indent/type")); + text_editor->set_indent_size(EDITOR_GET("text_editor/behavior/indent/size")); + text_editor->set_auto_indent_enabled(EDITOR_GET("text_editor/behavior/indent/auto_indent")); + + // Completion + text_editor->set_auto_brace_completion_enabled(EDITOR_GET("text_editor/completion/auto_brace_complete")); + + // Appearance: Guidelines + if (EDITOR_GET("text_editor/appearance/guidelines/show_line_length_guidelines")) { + TypedArray<int> guideline_cols; + guideline_cols.append(EDITOR_GET("text_editor/appearance/guidelines/line_length_guideline_hard_column")); + if (EDITOR_GET("text_editor/appearance/guidelines/line_length_guideline_soft_column") != guideline_cols[0]) { + guideline_cols.append(EDITOR_GET("text_editor/appearance/guidelines/line_length_guideline_soft_column")); + } + text_editor->set_line_length_guidelines(guideline_cols); } else { - return false; + text_editor->set_line_length_guidelines(TypedArray<int>()); } } -void CodeTextEditor::update_editor_settings() { - completion_font_color = EDITOR_GET("text_editor/highlighting/completion_font_color"); - completion_string_color = EDITOR_GET("text_editor/highlighting/string_color"); - completion_comment_color = EDITOR_GET("text_editor/highlighting/comment_color"); - - text_editor->set_highlight_all_occurrences(EditorSettings::get_singleton()->get("text_editor/highlighting/highlight_all_occurrences")); - text_editor->set_highlight_current_line(EditorSettings::get_singleton()->get("text_editor/highlighting/highlight_current_line")); - text_editor->set_indent_using_spaces(EditorSettings::get_singleton()->get("text_editor/indent/type")); - text_editor->set_indent_size(EditorSettings::get_singleton()->get("text_editor/indent/size")); - text_editor->set_auto_indent(EditorSettings::get_singleton()->get("text_editor/indent/auto_indent")); - text_editor->set_draw_tabs(EditorSettings::get_singleton()->get("text_editor/indent/draw_tabs")); - text_editor->set_draw_spaces(EditorSettings::get_singleton()->get("text_editor/indent/draw_spaces")); - text_editor->set_smooth_scroll_enabled(EditorSettings::get_singleton()->get("text_editor/navigation/smooth_scrolling")); - text_editor->set_v_scroll_speed(EditorSettings::get_singleton()->get("text_editor/navigation/v_scroll_speed")); - text_editor->set_draw_minimap(EditorSettings::get_singleton()->get("text_editor/navigation/show_minimap")); - text_editor->set_minimap_width((int)EditorSettings::get_singleton()->get("text_editor/navigation/minimap_width") * EDSCALE); - text_editor->set_draw_line_numbers(EditorSettings::get_singleton()->get("text_editor/appearance/show_line_numbers")); - text_editor->set_line_numbers_zero_padded(EditorSettings::get_singleton()->get("text_editor/appearance/line_numbers_zero_padded")); - text_editor->set_draw_bookmarks_gutter(EditorSettings::get_singleton()->get("text_editor/appearance/show_bookmark_gutter")); - text_editor->set_hiding_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(EditorSettings::get_singleton()->get("text_editor/completion/auto_brace_complete")); +void CodeTextEditor::set_find_replace_bar(FindReplaceBar *p_bar) { + if (find_replace_bar) { + return; + } + + find_replace_bar = p_bar; + find_replace_bar->set_text_edit(this); + find_replace_bar->connect("error", callable_mp(error, &Label::set_text)); +} + +void CodeTextEditor::remove_find_replace_bar() { + if (!find_replace_bar) { + return; + } + + find_replace_bar->disconnect("error", callable_mp(error, &Label::set_text)); + find_replace_bar = nullptr; } void CodeTextEditor::trim_trailing_whitespace() { @@ -970,8 +1101,9 @@ void CodeTextEditor::trim_trailing_whitespace() { } if (trimed_whitespace) { + text_editor->merge_overlapping_carets(); text_editor->end_complex_operation(); - text_editor->update(); + text_editor->queue_redraw(); } } @@ -989,20 +1121,23 @@ void CodeTextEditor::insert_final_newline() { text_editor->set_line(final_line, line); text_editor->end_complex_operation(); - text_editor->update(); + text_editor->queue_redraw(); } } void CodeTextEditor::convert_indent_to_spaces() { - int indent_size = EditorSettings::get_singleton()->get("text_editor/indent/size"); + int indent_size = EDITOR_GET("text_editor/behavior/indent/size"); String indent = ""; for (int i = 0; i < indent_size; i++) { indent += " "; } - int cursor_line = text_editor->cursor_get_line(); - int cursor_column = text_editor->cursor_get_column(); + Vector<int> cursor_columns; + cursor_columns.resize(text_editor->get_caret_count()); + for (int c = 0; c < text_editor->get_caret_count(); c++) { + cursor_columns.write[c] = text_editor->get_caret_column(c); + } bool changed_indentation = false; for (int i = 0; i < text_editor->get_line_count(); i++) { @@ -1019,10 +1154,12 @@ void CodeTextEditor::convert_indent_to_spaces() { text_editor->begin_complex_operation(); changed_indentation = true; } - if (cursor_line == i && cursor_column > j) { - cursor_column += indent_size - 1; + for (int c = 0; c < text_editor->get_caret_count(); c++) { + if (text_editor->get_caret_line(c) == i && text_editor->get_caret_column(c) > j) { + cursor_columns.write[c] += indent_size - 1; + } } - line = line.left(j) + indent + line.right(j + 1); + line = line.left(j) + indent + line.substr(j + 1); } j++; } @@ -1031,18 +1168,24 @@ void CodeTextEditor::convert_indent_to_spaces() { } } if (changed_indentation) { - text_editor->cursor_set_column(cursor_column); + for (int c = 0; c < text_editor->get_caret_count(); c++) { + text_editor->set_caret_column(cursor_columns[c], c == 0, c); + } + text_editor->merge_overlapping_carets(); text_editor->end_complex_operation(); - text_editor->update(); + text_editor->queue_redraw(); } } void CodeTextEditor::convert_indent_to_tabs() { - int indent_size = EditorSettings::get_singleton()->get("text_editor/indent/size"); + int indent_size = EDITOR_GET("text_editor/behavior/indent/size"); indent_size -= 1; - int cursor_line = text_editor->cursor_get_line(); - int cursor_column = text_editor->cursor_get_column(); + Vector<int> cursor_columns; + cursor_columns.resize(text_editor->get_caret_count()); + for (int c = 0; c < text_editor->get_caret_count(); c++) { + cursor_columns.write[c] = text_editor->get_caret_column(c); + } bool changed_indentation = false; for (int i = 0; i < text_editor->get_line_count(); i++) { @@ -1063,10 +1206,12 @@ void CodeTextEditor::convert_indent_to_tabs() { text_editor->begin_complex_operation(); changed_indentation = true; } - if (cursor_line == i && cursor_column > j) { - cursor_column -= indent_size; + for (int c = 0; c < text_editor->get_caret_count(); c++) { + if (text_editor->get_caret_line(c) == i && text_editor->get_caret_column(c) > j) { + cursor_columns.write[c] -= indent_size; + } } - line = line.left(j - indent_size) + "\t" + line.right(j + 1); + line = line.left(j - indent_size) + "\t" + line.substr(j + 1); j = 0; space_count = -1; } @@ -1080,68 +1225,141 @@ void CodeTextEditor::convert_indent_to_tabs() { } } if (changed_indentation) { - text_editor->cursor_set_column(cursor_column); + for (int c = 0; c < text_editor->get_caret_count(); c++) { + text_editor->set_caret_column(cursor_columns[c], c == 0, c); + } + text_editor->merge_overlapping_carets(); text_editor->end_complex_operation(); - text_editor->update(); + text_editor->queue_redraw(); } } void CodeTextEditor::convert_case(CaseStyle p_case) { - if (!text_editor->is_selection_active()) { + if (!text_editor->has_selection()) { return; } - text_editor->begin_complex_operation(); - int begin = text_editor->get_selection_from_line(); - int end = text_editor->get_selection_to_line(); - int begin_col = text_editor->get_selection_from_column(); - int end_col = text_editor->get_selection_to_column(); - - for (int i = begin; i <= end; i++) { - int len = text_editor->get_line(i).length(); - if (i == end) { - len = end_col; - } - if (i == begin) { - len -= begin_col; + Vector<int> caret_edit_order = text_editor->get_caret_index_edit_order(); + for (const int &c : caret_edit_order) { + if (!text_editor->has_selection(c)) { + continue; } - String new_line = text_editor->get_line(i).substr(i == begin ? begin_col : 0, len); - switch (p_case) { - case UPPER: { - new_line = new_line.to_upper(); - } break; - case LOWER: { - new_line = new_line.to_lower(); - } break; - case CAPITALIZE: { - new_line = new_line.capitalize(); - } break; - } + int begin = text_editor->get_selection_from_line(c); + int end = text_editor->get_selection_to_line(c); + int begin_col = text_editor->get_selection_from_column(c); + int end_col = text_editor->get_selection_to_column(c); - if (i == begin) { - new_line = text_editor->get_line(i).left(begin_col) + new_line; - } - if (i == end) { - new_line = new_line + text_editor->get_line(i).right(end_col); + for (int i = begin; i <= end; i++) { + int len = text_editor->get_line(i).length(); + if (i == end) { + len = end_col; + } + if (i == begin) { + len -= begin_col; + } + String new_line = text_editor->get_line(i).substr(i == begin ? begin_col : 0, len); + + switch (p_case) { + case UPPER: { + new_line = new_line.to_upper(); + } break; + case LOWER: { + new_line = new_line.to_lower(); + } break; + case CAPITALIZE: { + new_line = new_line.capitalize(); + } break; + } + + if (i == begin) { + new_line = text_editor->get_line(i).left(begin_col) + new_line; + } + if (i == end) { + new_line = new_line + text_editor->get_line(i).substr(end_col); + } + text_editor->set_line(i, new_line); } - text_editor->set_line(i, new_line); } text_editor->end_complex_operation(); } void CodeTextEditor::move_lines_up() { text_editor->begin_complex_operation(); - if (text_editor->is_selection_active()) { - int from_line = text_editor->get_selection_from_line(); - int from_col = text_editor->get_selection_from_column(); - int to_line = text_editor->get_selection_to_line(); - int to_column = text_editor->get_selection_to_column(); - for (int i = from_line; i <= to_line; i++) { - int line_id = i; - int next_id = i - 1; + Vector<int> carets_to_remove; + + Vector<int> caret_edit_order = text_editor->get_caret_index_edit_order(); + for (int i = 0; i < caret_edit_order.size(); i++) { + int c = caret_edit_order[i]; + int cl = text_editor->get_caret_line(c); + + bool swaped_caret = false; + for (int j = i + 1; j < caret_edit_order.size(); j++) { + if (text_editor->has_selection(caret_edit_order[j])) { + if (text_editor->get_selection_from_line() == cl) { + carets_to_remove.push_back(caret_edit_order[j]); + continue; + } + + if (text_editor->get_selection_to_line() == cl) { + if (text_editor->has_selection(c)) { + if (text_editor->get_selection_to_line(c) != cl) { + text_editor->select(cl + 1, 0, text_editor->get_selection_to_line(c), text_editor->get_selection_to_column(c), c); + break; + } + } + + carets_to_remove.push_back(c); + i = j - 1; + swaped_caret = true; + break; + } + break; + } + + if (text_editor->get_caret_line(caret_edit_order[j]) == cl) { + carets_to_remove.push_back(caret_edit_order[j]); + i = j; + continue; + } + break; + } + + if (swaped_caret) { + continue; + } + + if (text_editor->has_selection(c)) { + int from_line = text_editor->get_selection_from_line(c); + int from_col = text_editor->get_selection_from_column(c); + int to_line = text_editor->get_selection_to_line(c); + int to_column = text_editor->get_selection_to_column(c); + int cursor_line = text_editor->get_caret_line(c); + + for (int j = from_line; j <= to_line; j++) { + int line_id = j; + int next_id = j - 1; + + if (line_id == 0 || next_id < 0) { + return; + } + + text_editor->unfold_line(line_id); + text_editor->unfold_line(next_id); + + text_editor->swap_lines(line_id, next_id); + text_editor->set_caret_line(next_id, c == 0, true, 0, c); + } + int from_line_up = from_line > 0 ? from_line - 1 : from_line; + int to_line_up = to_line > 0 ? to_line - 1 : to_line; + int cursor_line_up = cursor_line > 0 ? cursor_line - 1 : cursor_line; + text_editor->select(from_line_up, from_col, to_line_up, to_column, c); + text_editor->set_caret_line(cursor_line_up, c == 0, true, 0, c); + } else { + int line_id = text_editor->get_caret_line(c); + int next_id = line_id - 1; if (line_id == 0 || next_id < 0) { return; @@ -1151,240 +1369,345 @@ void CodeTextEditor::move_lines_up() { text_editor->unfold_line(next_id); text_editor->swap_lines(line_id, next_id); - text_editor->cursor_set_line(next_id); - } - int from_line_up = from_line > 0 ? from_line - 1 : from_line; - int to_line_up = to_line > 0 ? to_line - 1 : to_line; - text_editor->select(from_line_up, from_col, to_line_up, to_column); - } else { - int line_id = text_editor->cursor_get_line(); - int next_id = line_id - 1; - - if (line_id == 0 || next_id < 0) { - return; + text_editor->set_caret_line(next_id, c == 0, true, 0, c); } - - text_editor->unfold_line(line_id); - text_editor->unfold_line(next_id); - - text_editor->swap_lines(line_id, next_id); - text_editor->cursor_set_line(next_id); } text_editor->end_complex_operation(); - text_editor->update(); + text_editor->merge_overlapping_carets(); + text_editor->queue_redraw(); } void CodeTextEditor::move_lines_down() { text_editor->begin_complex_operation(); - if (text_editor->is_selection_active()) { - int from_line = text_editor->get_selection_from_line(); - int from_col = text_editor->get_selection_from_column(); - int to_line = text_editor->get_selection_to_line(); - int to_column = text_editor->get_selection_to_column(); - for (int i = to_line; i >= from_line; i--) { - int line_id = i; - int next_id = i + 1; + Vector<int> carets_to_remove; + + Vector<int> caret_edit_order = text_editor->get_caret_index_edit_order(); + for (int i = 0; i < caret_edit_order.size(); i++) { + int c = caret_edit_order[i]; + int cl = text_editor->get_caret_line(c); + + bool swaped_caret = false; + for (int j = i + 1; j < caret_edit_order.size(); j++) { + if (text_editor->has_selection(caret_edit_order[j])) { + if (text_editor->get_selection_from_line() == cl) { + carets_to_remove.push_back(caret_edit_order[j]); + continue; + } + + if (text_editor->get_selection_to_line() == cl) { + if (text_editor->has_selection(c)) { + if (text_editor->get_selection_to_line(c) != cl) { + text_editor->select(cl + 1, 0, text_editor->get_selection_to_line(c), text_editor->get_selection_to_column(c), c); + break; + } + } + + carets_to_remove.push_back(c); + i = j - 1; + swaped_caret = true; + break; + } + break; + } + + if (text_editor->get_caret_line(caret_edit_order[j]) == cl) { + carets_to_remove.push_back(caret_edit_order[j]); + i = j; + continue; + } + break; + } + + if (swaped_caret) { + continue; + } + + if (text_editor->has_selection(c)) { + int from_line = text_editor->get_selection_from_line(c); + int from_col = text_editor->get_selection_from_column(c); + int to_line = text_editor->get_selection_to_line(c); + int to_column = text_editor->get_selection_to_column(c); + int cursor_line = text_editor->get_caret_line(c); + + for (int l = to_line; l >= from_line; l--) { + int line_id = l; + int next_id = l + 1; + + if (line_id == text_editor->get_line_count() - 1 || next_id > text_editor->get_line_count()) { + continue; + } + + text_editor->unfold_line(line_id); + text_editor->unfold_line(next_id); + + text_editor->swap_lines(line_id, next_id); + text_editor->set_caret_line(next_id, c == 0, true, 0, c); + } + int from_line_down = from_line < text_editor->get_line_count() ? from_line + 1 : from_line; + int to_line_down = to_line < text_editor->get_line_count() ? to_line + 1 : to_line; + int cursor_line_down = cursor_line < text_editor->get_line_count() ? cursor_line + 1 : cursor_line; + text_editor->select(from_line_down, from_col, to_line_down, to_column, c); + text_editor->set_caret_line(cursor_line_down, c == 0, true, 0, c); + } else { + int line_id = text_editor->get_caret_line(c); + int next_id = line_id + 1; if (line_id == text_editor->get_line_count() - 1 || next_id > text_editor->get_line_count()) { - return; + continue; } text_editor->unfold_line(line_id); text_editor->unfold_line(next_id); text_editor->swap_lines(line_id, next_id); - text_editor->cursor_set_line(next_id); - } - int from_line_down = from_line < text_editor->get_line_count() ? from_line + 1 : from_line; - int to_line_down = to_line < text_editor->get_line_count() ? to_line + 1 : to_line; - text_editor->select(from_line_down, from_col, to_line_down, to_column); - } else { - int line_id = text_editor->cursor_get_line(); - int next_id = line_id + 1; - - if (line_id == text_editor->get_line_count() - 1 || next_id > text_editor->get_line_count()) { - return; + text_editor->set_caret_line(next_id, c == 0, true, 0, c); } + } - text_editor->unfold_line(line_id); - text_editor->unfold_line(next_id); - - text_editor->swap_lines(line_id, next_id); - text_editor->cursor_set_line(next_id); + // Sort and remove backwards to preserve indexes. + carets_to_remove.sort(); + for (int i = carets_to_remove.size() - 1; i >= 0; i--) { + text_editor->remove_caret(carets_to_remove[i]); } + + text_editor->merge_overlapping_carets(); text_editor->end_complex_operation(); - text_editor->update(); + text_editor->queue_redraw(); } -void CodeTextEditor::_delete_line(int p_line) { +void CodeTextEditor::_delete_line(int p_line, int p_caret) { // this is currently intended to be called within delete_lines() // so `begin_complex_operation` is omitted here text_editor->set_line(p_line, ""); if (p_line == 0 && text_editor->get_line_count() > 1) { - text_editor->cursor_set_line(1); - text_editor->cursor_set_column(0); + text_editor->set_caret_line(1, p_caret == 0, true, 0, p_caret); + text_editor->set_caret_column(0, p_caret == 0, p_caret); } - text_editor->backspace_at_cursor(); - text_editor->unfold_line(p_line); - text_editor->cursor_set_line(p_line); + text_editor->backspace(p_caret); + if (p_line < text_editor->get_line_count()) { + text_editor->unfold_line(p_line); + } + text_editor->set_caret_line(p_line, p_caret == 0, true, 0, p_caret); } void CodeTextEditor::delete_lines() { text_editor->begin_complex_operation(); - if (text_editor->is_selection_active()) { - int to_line = text_editor->get_selection_to_line(); - int from_line = text_editor->get_selection_from_line(); - int count = Math::abs(to_line - from_line) + 1; - - text_editor->cursor_set_line(from_line, false); - for (int i = 0; i < count; i++) { - _delete_line(from_line); + + Vector<int> carets_to_remove; + + Vector<int> caret_edit_order = text_editor->get_caret_index_edit_order(); + for (int i = 0; i < caret_edit_order.size(); i++) { + int c = caret_edit_order[i]; + int cl = text_editor->get_caret_line(c); + + bool swaped_caret = false; + for (int j = i + 1; j < caret_edit_order.size(); j++) { + if (text_editor->has_selection(caret_edit_order[j])) { + if (text_editor->get_selection_from_line() == cl) { + carets_to_remove.push_back(caret_edit_order[j]); + continue; + } + + if (text_editor->get_selection_to_line() == cl) { + if (text_editor->has_selection(c)) { + if (text_editor->get_selection_to_line(c) != cl) { + text_editor->select(cl + 1, 0, text_editor->get_selection_to_line(c), text_editor->get_selection_to_column(c), c); + break; + } + } + + carets_to_remove.push_back(c); + i = j - 1; + swaped_caret = true; + break; + } + break; + } + + if (text_editor->get_caret_line(caret_edit_order[j]) == cl) { + carets_to_remove.push_back(caret_edit_order[j]); + i = j; + continue; + } + break; } - text_editor->deselect(); - } else { - _delete_line(text_editor->cursor_get_line()); - } - text_editor->end_complex_operation(); -} -void CodeTextEditor::clone_lines_down() { - const int cursor_column = text_editor->cursor_get_column(); - int from_line = text_editor->cursor_get_line(); - int to_line = text_editor->cursor_get_line(); - int from_column = 0; - int to_column = 0; - int cursor_new_line = to_line + 1; - int cursor_new_column = text_editor->cursor_get_column(); - String new_text = "\n" + text_editor->get_line(from_line); - bool selection_active = false; + if (swaped_caret) { + continue; + } - text_editor->cursor_set_column(text_editor->get_line(from_line).length()); - if (text_editor->is_selection_active()) { - from_column = text_editor->get_selection_from_column(); - to_column = text_editor->get_selection_to_column(); + if (text_editor->has_selection(c)) { + int to_line = text_editor->get_selection_to_line(c); + int from_line = text_editor->get_selection_from_line(c); + int count = Math::abs(to_line - from_line) + 1; - from_line = text_editor->get_selection_from_line(); - to_line = text_editor->get_selection_to_line(); - cursor_new_line = to_line + text_editor->cursor_get_line() - from_line; - cursor_new_column = to_column == cursor_column ? 2 * to_column - from_column : to_column; - new_text = text_editor->get_selection_text(); - selection_active = true; + text_editor->set_caret_line(from_line, false, true, 0, c); + text_editor->deselect(c); + for (int j = 0; j < count; j++) { + _delete_line(from_line, c); + } + } else { + _delete_line(text_editor->get_caret_line(c), c); + } + } - text_editor->cursor_set_line(to_line); - text_editor->cursor_set_column(to_column); + // Sort and remove backwards to preserve indexes. + carets_to_remove.sort(); + for (int i = carets_to_remove.size() - 1; i >= 0; i--) { + text_editor->remove_caret(carets_to_remove[i]); } + text_editor->merge_overlapping_carets(); + text_editor->end_complex_operation(); +} +void CodeTextEditor::duplicate_selection() { text_editor->begin_complex_operation(); - for (int i = from_line; i <= to_line; i++) { - text_editor->unfold_line(i); - } - text_editor->deselect(); - text_editor->insert_text_at_cursor(new_text); - text_editor->cursor_set_line(cursor_new_line); - text_editor->cursor_set_column(cursor_new_column); - if (selection_active) { - text_editor->select(to_line, to_column, 2 * to_line - from_line, to_line == from_line ? 2 * to_column - from_column : to_column); - } + Vector<int> caret_edit_order = text_editor->get_caret_index_edit_order(); + for (const int &c : caret_edit_order) { + const int cursor_column = text_editor->get_caret_column(c); + int from_line = text_editor->get_caret_line(c); + int to_line = text_editor->get_caret_line(c); + int from_column = 0; + int to_column = 0; + int cursor_new_line = to_line + 1; + int cursor_new_column = text_editor->get_caret_column(c); + String new_text = "\n" + text_editor->get_line(from_line); + bool selection_active = false; + + text_editor->set_caret_column(text_editor->get_line(from_line).length(), c == 0, c); + if (text_editor->has_selection(c)) { + from_column = text_editor->get_selection_from_column(c); + to_column = text_editor->get_selection_to_column(c); + + from_line = text_editor->get_selection_from_line(c); + to_line = text_editor->get_selection_to_line(c); + cursor_new_line = to_line + text_editor->get_caret_line(c) - from_line; + cursor_new_column = to_column == cursor_column ? 2 * to_column - from_column : to_column; + new_text = text_editor->get_selected_text(c); + selection_active = true; + + text_editor->set_caret_line(to_line, c == 0, true, 0, c); + text_editor->set_caret_column(to_column, c == 0, c); + } + for (int i = from_line; i <= to_line; i++) { + text_editor->unfold_line(i); + } + text_editor->deselect(c); + text_editor->insert_text_at_caret(new_text, c); + text_editor->set_caret_line(cursor_new_line, c == 0, true, 0, c); + text_editor->set_caret_column(cursor_new_column, c == 0, c); + if (selection_active) { + text_editor->select(to_line, to_column, 2 * to_line - from_line, to_line == from_line ? 2 * to_column - from_column : to_column, c); + } + } + text_editor->merge_overlapping_carets(); text_editor->end_complex_operation(); - text_editor->update(); + text_editor->queue_redraw(); } void CodeTextEditor::toggle_inline_comment(const String &delimiter) { text_editor->begin_complex_operation(); - if (text_editor->is_selection_active()) { - int begin = text_editor->get_selection_from_line(); - int end = text_editor->get_selection_to_line(); - // End of selection ends on the first column of the last line, ignore it. - if (text_editor->get_selection_to_column() == 0) { - end -= 1; - } + Vector<int> caret_edit_order = text_editor->get_caret_index_edit_order(); + for (const int &c : caret_edit_order) { + if (text_editor->has_selection(c)) { + int begin = text_editor->get_selection_from_line(c); + int end = text_editor->get_selection_to_line(c); - int col_to = text_editor->get_selection_to_column(); - int cursor_pos = text_editor->cursor_get_column(); + // End of selection ends on the first column of the last line, ignore it. + if (text_editor->get_selection_to_column(c) == 0) { + end -= 1; + } - // Check if all lines in the selected block are commented. - bool is_commented = true; - for (int i = begin; i <= end; i++) { - if (!text_editor->get_line(i).begins_with(delimiter)) { - is_commented = false; - break; + int col_to = text_editor->get_selection_to_column(c); + int cursor_pos = text_editor->get_caret_column(c); + + // Check if all lines in the selected block are commented. + bool is_commented = true; + for (int i = begin; i <= end; i++) { + if (!text_editor->get_line(i).begins_with(delimiter)) { + is_commented = false; + break; + } } - } - for (int i = begin; i <= end; i++) { - String line_text = text_editor->get_line(i); + for (int i = begin; i <= end; i++) { + String line_text = text_editor->get_line(i); - if (line_text.strip_edges().empty()) { - line_text = delimiter; - } else { - if (is_commented) { - line_text = line_text.substr(delimiter.length(), line_text.length()); + if (line_text.strip_edges().is_empty()) { + line_text = delimiter; } else { - line_text = delimiter + line_text; + if (is_commented) { + line_text = line_text.substr(delimiter.length(), line_text.length()); + } else { + line_text = delimiter + line_text; + } } + text_editor->set_line(i, line_text); } - text_editor->set_line(i, line_text); - } - // Adjust selection & cursor position. - int offset = (is_commented ? -1 : 1) * delimiter.length(); - int col_from = text_editor->get_selection_from_column() > 0 ? text_editor->get_selection_from_column() + offset : 0; + // Adjust selection & cursor position. + int offset = (is_commented ? -1 : 1) * delimiter.length(); + int col_from = text_editor->get_selection_from_column(c) > 0 ? text_editor->get_selection_from_column(c) + offset : 0; - if (is_commented && text_editor->cursor_get_column() == text_editor->get_line(text_editor->cursor_get_line()).length() + 1) { - cursor_pos += 1; - } + if (is_commented && text_editor->get_caret_column(c) == text_editor->get_line(text_editor->get_caret_line(c)).length() + 1) { + cursor_pos += 1; + } - if (text_editor->get_selection_to_column() != 0 && col_to != text_editor->get_line(text_editor->get_selection_to_line()).length() + 1) { - col_to += offset; - } + if (text_editor->get_selection_to_column(c) != 0 && col_to != text_editor->get_line(text_editor->get_selection_to_line(c)).length() + 1) { + col_to += offset; + } - if (text_editor->cursor_get_column() != 0) { - cursor_pos += offset; - } + if (text_editor->get_caret_column(c) != 0) { + cursor_pos += offset; + } - text_editor->select(begin, col_from, text_editor->get_selection_to_line(), col_to); - text_editor->cursor_set_column(cursor_pos); + text_editor->select(begin, col_from, text_editor->get_selection_to_line(c), col_to, c); + text_editor->set_caret_column(cursor_pos, c == 0, c); - } else { - int begin = text_editor->cursor_get_line(); - String line_text = text_editor->get_line(begin); - int delimiter_length = delimiter.length(); - - int col = text_editor->cursor_get_column(); - if (line_text.begins_with(delimiter)) { - line_text = line_text.substr(delimiter_length, line_text.length()); - col -= delimiter_length; } else { - line_text = delimiter + line_text; - col += delimiter_length; - } + int begin = text_editor->get_caret_line(c); + String line_text = text_editor->get_line(begin); + int delimiter_length = delimiter.length(); + + int col = text_editor->get_caret_column(c); + if (line_text.begins_with(delimiter)) { + line_text = line_text.substr(delimiter_length, line_text.length()); + col -= delimiter_length; + } else { + line_text = delimiter + line_text; + col += delimiter_length; + } - text_editor->set_line(begin, line_text); - text_editor->cursor_set_column(col); + text_editor->set_line(begin, line_text); + text_editor->set_caret_column(col, c == 0, c); + } } + text_editor->merge_overlapping_carets(); text_editor->end_complex_operation(); - text_editor->update(); + text_editor->queue_redraw(); } void CodeTextEditor::goto_line(int p_line) { + text_editor->remove_secondary_carets(); text_editor->deselect(); text_editor->unfold_line(p_line); - text_editor->call_deferred("cursor_set_line", p_line); + text_editor->call_deferred(SNAME("set_caret_line"), p_line); } void CodeTextEditor::goto_line_selection(int p_line, int p_begin, int p_end) { + text_editor->remove_secondary_carets(); text_editor->unfold_line(p_line); - text_editor->call_deferred("cursor_set_line", p_line); - text_editor->call_deferred("cursor_set_column", p_begin); + text_editor->call_deferred(SNAME("set_caret_line"), p_line); + text_editor->call_deferred(SNAME("set_caret_column"), p_begin); text_editor->select(p_line, p_begin, p_line, p_end); } void CodeTextEditor::goto_line_centered(int p_line) { goto_line(p_line); - text_editor->call_deferred("center_viewport_to_cursor"); + text_editor->call_deferred(SNAME("center_viewport_to_caret")); } void CodeTextEditor::set_executing_line(int p_line) { @@ -1397,19 +1720,7 @@ void CodeTextEditor::clear_executing_line() { Variant CodeTextEditor::get_edit_state() { Dictionary state; - - state["scroll_position"] = text_editor->get_v_scroll(); - state["h_scroll_position"] = text_editor->get_h_scroll(); - state["column"] = text_editor->cursor_get_column(); - state["row"] = text_editor->cursor_get_line(); - - state["selection"] = get_text_editor()->is_selection_active(); - if (get_text_editor()->is_selection_active()) { - state["selection_from_line"] = text_editor->get_selection_from_line(); - state["selection_from_column"] = text_editor->get_selection_from_column(); - state["selection_to_line"] = text_editor->get_selection_to_line(); - state["selection_to_column"] = text_editor->get_selection_to_column(); - } + state.merge(get_navigation_state()); state["folded_lines"] = text_editor->get_folded_lines(); state["breakpoints"] = text_editor->get_breakpointed_lines(); @@ -1425,13 +1736,15 @@ void CodeTextEditor::set_edit_state(const Variant &p_state) { Dictionary state = p_state; /* update the row first as it sets the column to 0 */ - text_editor->cursor_set_line(state["row"]); - text_editor->cursor_set_column(state["column"]); + text_editor->set_caret_line(state["row"]); + text_editor->set_caret_column(state["column"]); text_editor->set_v_scroll(state["scroll_position"]); text_editor->set_h_scroll(state["h_scroll_position"]); - if (state.has("selection")) { + if (state.get("selection", false)) { text_editor->select(state["selection_from_line"], state["selection_from_column"], state["selection_to_line"], state["selection_to_column"]); + } else { + text_editor->deselect(); } if (state.has("folded_lines")) { @@ -1456,9 +1769,28 @@ void CodeTextEditor::set_edit_state(const Variant &p_state) { } } +Variant CodeTextEditor::get_navigation_state() { + Dictionary state; + + state["scroll_position"] = text_editor->get_v_scroll(); + state["h_scroll_position"] = text_editor->get_h_scroll(); + state["column"] = text_editor->get_caret_column(); + state["row"] = text_editor->get_caret_line(); + + state["selection"] = get_text_editor()->has_selection(); + if (get_text_editor()->has_selection()) { + state["selection_from_line"] = text_editor->get_selection_from_line(); + state["selection_from_column"] = text_editor->get_selection_from_column(); + state["selection_to_line"] = text_editor->get_selection_to_line(); + state["selection_to_column"] = text_editor->get_selection_to_column(); + } + + return state; +} + void CodeTextEditor::set_error(const String &p_error) { error->set_text(p_error); - if (p_error != "") { + if (!p_error.is_empty()) { error->set_default_cursor_shape(CURSOR_POINTING_HAND); } else { error->set_default_cursor_shape(CURSOR_ARROW); @@ -1470,146 +1802,217 @@ void CodeTextEditor::set_error_pos(int p_line, int p_column) { error_column = p_column; } +Point2i CodeTextEditor::get_error_pos() const { + return Point2i(error_line, error_column); +} + void CodeTextEditor::goto_error() { - if (error->get_text() != "") { - text_editor->cursor_set_line(error_line); - text_editor->cursor_set_column(error_column); - text_editor->center_viewport_to_cursor(); + if (!error->get_text().is_empty()) { + if (text_editor->get_line_count() != error_line) { + text_editor->unfold_line(error_line); + } + text_editor->remove_secondary_carets(); + text_editor->set_caret_line(error_line); + text_editor->set_caret_column(error_column); + text_editor->center_viewport_to_caret(); } } -void CodeTextEditor::_update_font() { - text_editor->add_theme_font_override("font", get_theme_font("source", "EditorFonts")); +void CodeTextEditor::_update_text_editor_theme() { + emit_signal(SNAME("load_theme_settings")); - error->add_theme_font_override("font", get_theme_font("status_source", "EditorFonts")); - error->add_theme_color_override("font_color", get_theme_color("error_color", "Editor")); + error->begin_bulk_theme_override(); + error->add_theme_font_override(SNAME("font"), get_theme_font(SNAME("status_source"), SNAME("EditorFonts"))); + error->add_theme_font_size_override(SNAME("font_size"), get_theme_font_size(SNAME("status_source_size"), SNAME("EditorFonts"))); + error->add_theme_color_override(SNAME("font_color"), get_theme_color(SNAME("error_color"), SNAME("Editor"))); - Ref<Font> status_bar_font = get_theme_font("status_source", "EditorFonts"); + Ref<Font> status_bar_font = get_theme_font(SNAME("status_source"), SNAME("EditorFonts")); + int status_bar_font_size = get_theme_font_size(SNAME("status_source_size"), SNAME("EditorFonts")); error->add_theme_font_override("font", status_bar_font); + error->add_theme_font_size_override("font_size", status_bar_font_size); int count = status_bar->get_child_count(); for (int i = 0; i < count; i++) { Control *n = Object::cast_to<Control>(status_bar->get_child(i)); if (n) { n->add_theme_font_override("font", status_bar_font); + n->add_theme_font_size_override("font_size", status_bar_font_size); } } + error->end_bulk_theme_override(); } void CodeTextEditor::_on_settings_change() { - _update_font(); + _apply_settings_change(); +} - font_size = EditorSettings::get_singleton()->get("interface/editor/code_font_size"); +void CodeTextEditor::_apply_settings_change() { + _update_text_editor_theme(); - // Auto brace completion. - text_editor->set_auto_brace_completion( - EDITOR_GET("text_editor/completion/auto_brace_complete")); + font_size = EDITOR_GET("interface/editor/code_font_size"); + int ot_mode = EDITOR_GET("interface/editor/code_font_contextual_ligatures"); - code_complete_timer->set_wait_time( - EDITOR_GET("text_editor/completion/code_complete_delay")); + Ref<FontVariation> fc = text_editor->get_theme_font(SNAME("font")); + if (fc.is_valid()) { + switch (ot_mode) { + case 1: { // Disable ligatures. + Dictionary ftrs; + ftrs[TS->name_to_tag("calt")] = 0; + fc->set_opentype_features(ftrs); + } break; + case 2: { // Custom. + Vector<String> subtag = String(EDITOR_GET("interface/editor/code_font_custom_opentype_features")).split(","); + Dictionary ftrs; + for (int i = 0; i < subtag.size(); i++) { + Vector<String> subtag_a = subtag[i].split("="); + if (subtag_a.size() == 2) { + ftrs[TS->name_to_tag(subtag_a[0])] = subtag_a[1].to_int(); + } else if (subtag_a.size() == 1) { + ftrs[TS->name_to_tag(subtag_a[0])] = 1; + } + } + fc->set_opentype_features(ftrs); + } break; + default: { // Default. + Dictionary ftrs; + ftrs[TS->name_to_tag("calt")] = 1; + fc->set_opentype_features(ftrs); + } break; + } + } - // Call hint settings. - text_editor->set_callhint_settings( - EDITOR_GET("text_editor/completion/put_callhint_tooltip_below_current_line"), - EDITOR_GET("text_editor/completion/callhint_tooltip_offset")); + text_editor->set_code_hint_draw_below(EDITOR_GET("text_editor/completion/put_callhint_tooltip_below_current_line")); + code_complete_timer->set_wait_time(EDITOR_GET("text_editor/completion/code_complete_delay")); idle->set_wait_time(EDITOR_GET("text_editor/completion/idle_parse_delay")); } void CodeTextEditor::_text_changed_idle_timeout() { _validate_script(); - emit_signal("validate_script"); + emit_signal(SNAME("validate_script")); } void CodeTextEditor::validate_script() { idle->start(); } -void CodeTextEditor::_warning_label_gui_input(const Ref<InputEvent> &p_event) { - Ref<InputEventMouseButton> mb = p_event; - if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { - _warning_button_pressed(); - } +void CodeTextEditor::_error_button_pressed() { + _set_show_errors_panel(!is_errors_panel_opened); + _set_show_warnings_panel(false); } void CodeTextEditor::_warning_button_pressed() { _set_show_warnings_panel(!is_warnings_panel_opened); + _set_show_errors_panel(false); +} + +void CodeTextEditor::_set_show_errors_panel(bool p_show) { + is_errors_panel_opened = p_show; + emit_signal(SNAME("show_errors_panel"), p_show); } void CodeTextEditor::_set_show_warnings_panel(bool p_show) { is_warnings_panel_opened = p_show; - emit_signal("show_warnings_panel", p_show); + emit_signal(SNAME("show_warnings_panel"), p_show); } void CodeTextEditor::_toggle_scripts_pressed() { - toggle_scripts_button->set_icon(ScriptEditor::get_singleton()->toggle_scripts_panel() ? get_theme_icon("Back", "EditorIcons") : get_theme_icon("Forward", "EditorIcons")); + ScriptEditor::get_singleton()->toggle_scripts_panel(); + update_toggle_scripts_button(); } void CodeTextEditor::_error_pressed(const Ref<InputEvent> &p_event) { Ref<InputEventMouseButton> mb = p_event; - if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { + if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) { goto_error(); } } +void CodeTextEditor::_update_status_bar_theme() { + error_button->set_icon(get_theme_icon(SNAME("StatusError"), SNAME("EditorIcons"))); + error_button->add_theme_color_override("font_color", get_theme_color(SNAME("error_color"), SNAME("Editor"))); + error_button->add_theme_font_override("font", get_theme_font(SNAME("status_source"), SNAME("EditorFonts"))); + error_button->add_theme_font_size_override("font_size", get_theme_font_size(SNAME("status_source_size"), SNAME("EditorFonts"))); + + warning_button->set_icon(get_theme_icon(SNAME("NodeWarning"), SNAME("EditorIcons"))); + warning_button->add_theme_color_override("font_color", get_theme_color(SNAME("warning_color"), SNAME("Editor"))); + warning_button->add_theme_font_override("font", get_theme_font(SNAME("status_source"), SNAME("EditorFonts"))); + warning_button->add_theme_font_size_override("font_size", get_theme_font_size(SNAME("status_source_size"), SNAME("EditorFonts"))); + + line_and_col_txt->add_theme_font_override("font", get_theme_font(SNAME("status_source"), SNAME("EditorFonts"))); + line_and_col_txt->add_theme_font_size_override("font_size", get_theme_font_size(SNAME("status_source_size"), SNAME("EditorFonts"))); +} + void CodeTextEditor::_notification(int p_what) { switch (p_what) { - case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { - _load_theme_settings(); - emit_signal("load_theme_settings"); + case NOTIFICATION_ENTER_TREE: { + _update_status_bar_theme(); } break; + case NOTIFICATION_THEME_CHANGED: { + _update_status_bar_theme(); if (toggle_scripts_button->is_visible()) { update_toggle_scripts_button(); } - _update_font(); - } break; - case NOTIFICATION_ENTER_TREE: { - warning_button->set_icon(get_theme_icon("NodeWarning", "EditorIcons")); - add_theme_constant_override("separation", 4 * EDSCALE); + _update_text_editor_theme(); } break; + case NOTIFICATION_VISIBILITY_CHANGED: { if (toggle_scripts_button->is_visible()) { update_toggle_scripts_button(); } set_process_input(is_visible_in_tree()); } break; - default: - break; + + case NOTIFICATION_PREDELETE: { + if (find_replace_bar) { + find_replace_bar->set_text_edit(nullptr); + } + } break; } } -void CodeTextEditor::set_warning_nb(int p_warning_nb) { - warning_count_label->set_text(itos(p_warning_nb)); - warning_count_label->set_visible(p_warning_nb > 0); - warning_button->set_visible(p_warning_nb > 0); - if (!p_warning_nb) { +void CodeTextEditor::set_error_count(int p_error_count) { + error_button->set_text(itos(p_error_count)); + error_button->set_visible(p_error_count > 0); + if (!p_error_count) { + _set_show_errors_panel(false); + } +} + +void CodeTextEditor::set_warning_count(int p_warning_count) { + warning_button->set_text(itos(p_warning_count)); + warning_button->set_visible(p_warning_count > 0); + if (!p_warning_count) { _set_show_warnings_panel(false); } } void CodeTextEditor::toggle_bookmark() { - int line = text_editor->cursor_get_line(); - text_editor->set_line_as_bookmarked(line, !text_editor->is_line_bookmarked(line)); + for (int i = 0; i < text_editor->get_caret_count(); i++) { + int line = text_editor->get_caret_line(i); + text_editor->set_line_as_bookmarked(line, !text_editor->is_line_bookmarked(line)); + } } void CodeTextEditor::goto_next_bookmark() { - Array bmarks = text_editor->get_bookmarked_lines(); + PackedInt32Array bmarks = text_editor->get_bookmarked_lines(); if (bmarks.size() <= 0) { return; } - int line = text_editor->cursor_get_line(); + text_editor->remove_secondary_carets(); + int line = text_editor->get_caret_line(); if (line >= (int)bmarks[bmarks.size() - 1]) { text_editor->unfold_line(bmarks[0]); - text_editor->cursor_set_line(bmarks[0]); - text_editor->center_viewport_to_cursor(); + text_editor->set_caret_line(bmarks[0]); + text_editor->center_viewport_to_caret(); } else { for (int i = 0; i < bmarks.size(); i++) { int bmark_line = bmarks[i]; if (bmark_line > line) { text_editor->unfold_line(bmark_line); - text_editor->cursor_set_line(bmark_line); - text_editor->center_viewport_to_cursor(); + text_editor->set_caret_line(bmark_line); + text_editor->center_viewport_to_caret(); return; } } @@ -1617,23 +2020,24 @@ void CodeTextEditor::goto_next_bookmark() { } void CodeTextEditor::goto_prev_bookmark() { - Array bmarks = text_editor->get_bookmarked_lines(); + PackedInt32Array bmarks = text_editor->get_bookmarked_lines(); if (bmarks.size() <= 0) { return; } - int line = text_editor->cursor_get_line(); + text_editor->remove_secondary_carets(); + int line = text_editor->get_caret_line(); if (line <= (int)bmarks[0]) { text_editor->unfold_line(bmarks[bmarks.size() - 1]); - text_editor->cursor_set_line(bmarks[bmarks.size() - 1]); - text_editor->center_viewport_to_cursor(); + text_editor->set_caret_line(bmarks[bmarks.size() - 1]); + text_editor->center_viewport_to_caret(); } else { - for (int i = bmarks.size(); i >= 0; i--) { + for (int i = bmarks.size() - 1; i >= 0; i--) { int bmark_line = bmarks[i]; if (bmark_line < line) { text_editor->unfold_line(bmark_line); - text_editor->cursor_set_line(bmark_line); - text_editor->center_viewport_to_cursor(); + text_editor->set_caret_line(bmark_line); + text_editor->center_viewport_to_caret(); return; } } @@ -1645,10 +2049,9 @@ void CodeTextEditor::remove_all_bookmarks() { } void CodeTextEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_input"), &CodeTextEditor::_input); - ADD_SIGNAL(MethodInfo("validate_script")); ADD_SIGNAL(MethodInfo("load_theme_settings")); + ADD_SIGNAL(MethodInfo("show_errors_panel")); ADD_SIGNAL(MethodInfo("show_warnings_panel")); } @@ -1662,31 +2065,59 @@ void CodeTextEditor::show_toggle_scripts_button() { } void CodeTextEditor::update_toggle_scripts_button() { - toggle_scripts_button->set_icon(ScriptEditor::get_singleton()->is_scripts_panel_toggled() ? get_theme_icon("Back", "EditorIcons") : get_theme_icon("Forward", "EditorIcons")); - toggle_scripts_button->set_tooltip(TTR("Toggle Scripts Panel") + " (" + ED_GET_SHORTCUT("script_editor/toggle_scripts_panel")->get_as_text() + ")"); + if (is_layout_rtl()) { + toggle_scripts_button->set_icon(get_theme_icon(ScriptEditor::get_singleton()->is_scripts_panel_toggled() ? SNAME("Forward") : SNAME("Back"), SNAME("EditorIcons"))); + } else { + toggle_scripts_button->set_icon(get_theme_icon(ScriptEditor::get_singleton()->is_scripts_panel_toggled() ? SNAME("Back") : SNAME("Forward"), SNAME("EditorIcons"))); + } + toggle_scripts_button->set_tooltip_text(vformat("%s (%s)", TTR("Toggle Scripts Panel"), ED_GET_SHORTCUT("script_editor/toggle_scripts_panel")->get_as_text())); } CodeTextEditor::CodeTextEditor() { code_complete_func = nullptr; - ED_SHORTCUT("script_editor/zoom_in", TTR("Zoom In"), KEY_MASK_CMD | KEY_EQUAL); - ED_SHORTCUT("script_editor/zoom_out", TTR("Zoom Out"), KEY_MASK_CMD | KEY_MINUS); - ED_SHORTCUT("script_editor/reset_zoom", TTR("Reset Zoom"), KEY_MASK_CMD | KEY_0); + ED_SHORTCUT("script_editor/zoom_in", TTR("Zoom In"), KeyModifierMask::CMD_OR_CTRL | Key::EQUAL); + ED_SHORTCUT("script_editor/zoom_out", TTR("Zoom Out"), KeyModifierMask::CMD_OR_CTRL | Key::MINUS); + ED_SHORTCUT_ARRAY("script_editor/reset_zoom", TTR("Reset Zoom"), + { int32_t(KeyModifierMask::CMD_OR_CTRL | Key::KEY_0), int32_t(KeyModifierMask::CMD_OR_CTRL | Key::KP_0) }); text_editor = memnew(CodeEdit); add_child(text_editor); text_editor->set_v_size_flags(SIZE_EXPAND_FILL); - // Added second so it opens at the bottom, so it won't shift the entire text editor when opening. - find_replace_bar = memnew(FindReplaceBar); - add_child(find_replace_bar); - find_replace_bar->set_h_size_flags(SIZE_EXPAND_FILL); - find_replace_bar->hide(); - - find_replace_bar->set_text_edit(text_editor); + int ot_mode = EDITOR_GET("interface/editor/code_font_contextual_ligatures"); + Ref<FontVariation> fc = text_editor->get_theme_font(SNAME("font")); + if (fc.is_valid()) { + switch (ot_mode) { + case 1: { // Disable ligatures. + Dictionary ftrs; + ftrs[TS->name_to_tag("calt")] = 0; + fc->set_opentype_features(ftrs); + } break; + case 2: { // Custom. + Vector<String> subtag = String(EDITOR_GET("interface/editor/code_font_custom_opentype_features")).split(","); + Dictionary ftrs; + for (int i = 0; i < subtag.size(); i++) { + Vector<String> subtag_a = subtag[i].split("="); + if (subtag_a.size() == 2) { + ftrs[TS->name_to_tag(subtag_a[0])] = subtag_a[1].to_int(); + } else if (subtag_a.size() == 1) { + ftrs[TS->name_to_tag(subtag_a[0])] = 1; + } + } + fc->set_opentype_features(ftrs); + } break; + default: { // Default. + Dictionary ftrs; + ftrs[TS->name_to_tag("calt")] = 1; + fc->set_opentype_features(ftrs); + } break; + } + } text_editor->set_draw_line_numbers(true); - text_editor->set_brace_matching(true); - text_editor->set_auto_indent(true); + text_editor->set_highlight_matching_braces_enabled(true); + text_editor->set_auto_indent_enabled(true); + text_editor->set_deselect_on_focus_loss_enabled(false); status_bar = memnew(HBoxContainer); add_child(status_bar); @@ -1716,7 +2147,7 @@ CodeTextEditor::CodeTextEditor() { ScrollContainer *scroll = memnew(ScrollContainer); scroll->set_h_size_flags(SIZE_EXPAND_FILL); scroll->set_v_size_flags(SIZE_EXPAND_FILL); - scroll->set_enable_v_scroll(false); + scroll->set_vertical_scroll_mode(ScrollContainer::SCROLL_MODE_DISABLED); status_bar->add_child(scroll); error = memnew(Label); @@ -1724,7 +2155,16 @@ CodeTextEditor::CodeTextEditor() { error->set_v_size_flags(SIZE_EXPAND | SIZE_SHRINK_CENTER); error->set_mouse_filter(MOUSE_FILTER_STOP); error->connect("gui_input", callable_mp(this, &CodeTextEditor::_error_pressed)); - find_replace_bar->connect("error", callable_mp(error, &Label::set_text)); + + // Errors + error_button = memnew(Button); + error_button->set_flat(true); + status_bar->add_child(error_button); + error_button->set_v_size_flags(SIZE_EXPAND | SIZE_SHRINK_CENTER); + error_button->set_default_cursor_shape(CURSOR_POINTING_HAND); + error_button->connect("pressed", callable_mp(this, &CodeTextEditor::_error_button_pressed)); + error_button->set_tooltip_text(TTR("Errors")); + set_error_count(0); // Warnings warning_button = memnew(Button); @@ -1733,48 +2173,36 @@ CodeTextEditor::CodeTextEditor() { warning_button->set_v_size_flags(SIZE_EXPAND | SIZE_SHRINK_CENTER); warning_button->set_default_cursor_shape(CURSOR_POINTING_HAND); warning_button->connect("pressed", callable_mp(this, &CodeTextEditor::_warning_button_pressed)); - warning_button->set_tooltip(TTR("Warnings")); - - warning_count_label = memnew(Label); - status_bar->add_child(warning_count_label); - warning_count_label->set_v_size_flags(SIZE_EXPAND | SIZE_SHRINK_CENTER); - warning_count_label->set_align(Label::ALIGN_RIGHT); - warning_count_label->set_default_cursor_shape(CURSOR_POINTING_HAND); - warning_count_label->set_mouse_filter(MOUSE_FILTER_STOP); - warning_count_label->set_tooltip(TTR("Warnings")); - warning_count_label->add_theme_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_theme_color("warning_color", "Editor")); - warning_count_label->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font("status_source", "EditorFonts")); - warning_count_label->connect("gui_input", callable_mp(this, &CodeTextEditor::_warning_label_gui_input)); - - is_warnings_panel_opened = false; - set_warning_nb(0); + warning_button->set_tooltip_text(TTR("Warnings")); + set_warning_count(0); // Line and column line_and_col_txt = memnew(Label); status_bar->add_child(line_and_col_txt); line_and_col_txt->set_v_size_flags(SIZE_EXPAND | SIZE_SHRINK_CENTER); - line_and_col_txt->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font("status_source", "EditorFonts")); - line_and_col_txt->set_tooltip(TTR("Line and column numbers.")); + line_and_col_txt->set_tooltip_text(TTR("Line and column numbers.")); line_and_col_txt->set_mouse_filter(MOUSE_FILTER_STOP); text_editor->connect("gui_input", callable_mp(this, &CodeTextEditor::_text_editor_gui_input)); - text_editor->connect("cursor_changed", callable_mp(this, &CodeTextEditor::_line_col_changed)); + text_editor->connect("caret_changed", callable_mp(this, &CodeTextEditor::_line_col_changed)); text_editor->connect("text_changed", callable_mp(this, &CodeTextEditor::_text_changed)); - text_editor->connect("request_completion", callable_mp(this, &CodeTextEditor::_complete_request)); - Vector<String> cs; + text_editor->connect("code_completion_requested", callable_mp(this, &CodeTextEditor::_complete_request)); + TypedArray<String> cs; cs.push_back("."); cs.push_back(","); cs.push_back("("); cs.push_back("="); cs.push_back("$"); cs.push_back("@"); - text_editor->set_completion(true, cs); + cs.push_back("\""); + cs.push_back("\'"); + text_editor->set_code_completion_prefixes(cs); idle->connect("timeout", callable_mp(this, &CodeTextEditor::_text_changed_idle_timeout)); code_complete_timer->connect("timeout", callable_mp(this, &CodeTextEditor::_code_complete_timer_timeout)); font_resize_val = 0; - font_size = EditorSettings::get_singleton()->get("interface/editor/code_font_size"); + font_size = EDITOR_GET("interface/editor/code_font_size"); font_resize_timer = memnew(Timer); add_child(font_resize_timer); font_resize_timer->set_one_shot(true); @@ -1782,4 +2210,5 @@ CodeTextEditor::CodeTextEditor() { font_resize_timer->connect("timeout", callable_mp(this, &CodeTextEditor::_font_resize_timeout)); EditorSettings::get_singleton()->connect("settings_changed", callable_mp(this, &CodeTextEditor::_on_settings_change)); + add_theme_constant_override("separation", 4 * EDSCALE); } |