summaryrefslogtreecommitdiff
path: root/editor/code_editor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/code_editor.cpp')
-rw-r--r--editor/code_editor.cpp442
1 files changed, 265 insertions, 177 deletions
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp
index 3ea970a0f0..f4717830bc 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-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 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,15 +32,15 @@
#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 "scene/resources/font.h"
-void GotoLineDialog::popup_find_line(TextEdit *p_edit) {
+void GotoLineDialog::popup_find_line(CodeEdit *p_edit) {
text_editor = p_edit;
line->set_text(itos(text_editor->cursor_get_line()));
@@ -66,10 +66,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,6 +81,8 @@ GotoLineDialog::GotoLineDialog() {
register_text_enter(line);
text_editor = nullptr;
+ line_label = nullptr;
+
set_hide_on_ok(false);
}
@@ -108,22 +110,25 @@ void FindReplaceBar::_notification(int p_what) {
void FindReplaceBar::_unhandled_input(const Ref<InputEvent> &p_event) {
Ref<InputEventKey> k = p_event;
- if (k.is_valid()) {
- if (k->is_pressed() && (text_edit->has_focus() || vbc_lineedit->is_a_parent_of(get_focus_owner()))) {
- bool accepted = true;
-
- switch (k->get_keycode()) {
- case KEY_ESCAPE: {
- _hide_bar();
- } break;
- default: {
- accepted = false;
- } break;
- }
+ if (!k.is_valid() || !k->is_pressed()) {
+ return;
+ }
- if (accepted) {
- accept_event();
- }
+ Control *focus_owner = get_focus_owner();
+ if (text_editor->has_focus() || (focus_owner && vbc_lineedit->is_a_parent_of(focus_owner))) {
+ bool accepted = true;
+
+ switch (k->get_keycode()) {
+ case KEY_ESCAPE: {
+ _hide_bar();
+ } break;
+ default: {
+ accepted = false;
+ } break;
+ }
+
+ if (accepted) {
+ accept_event();
}
}
}
@@ -132,20 +137,20 @@ bool FindReplaceBar::_search(uint32_t p_flags, int p_from_line, int p_from_col)
int line, col;
String text = get_search_text();
- bool found = text_edit->search(text, p_flags, p_from_line, p_from_col, line, col);
+ bool found = text_editor->search(text, p_flags, p_from_line, p_from_col, line, col);
if (found) {
if (!preserve_cursor) {
- text_edit->unfold_line(line);
- text_edit->cursor_set_line(line, false);
- text_edit->cursor_set_column(col + text.length(), false);
- text_edit->center_viewport_to_cursor();
- text_edit->select(line, col, line, col + text.length());
+ 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());
}
- text_edit->set_search_text(text);
- text_edit->set_search_flags(p_flags);
- text_edit->set_current_search_result(line, col);
+ 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;
@@ -155,9 +160,9 @@ bool FindReplaceBar::_search(uint32_t p_flags, int p_from_line, int p_from_col)
results_count = 0;
result_line = -1;
result_col = -1;
- text_edit->set_search_text("");
- text_edit->set_search_flags(p_flags);
- text_edit->set_current_search_result(line, col);
+ text_editor->set_search_text("");
+ text_editor->set_search_flags(p_flags);
+ text_editor->set_current_search_result(line, col);
}
_update_matches_label();
@@ -166,40 +171,67 @@ bool FindReplaceBar::_search(uint32_t p_flags, int p_from_line, int p_from_col)
}
void FindReplaceBar::_replace() {
- if (result_line != -1 && result_col != -1) {
- text_edit->begin_complex_operation();
+ bool selection_enabled = text_editor->is_selection_active();
+ 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());
+ }
- text_edit->unfold_line(result_line);
- text_edit->select(result_line, result_col, result_line, result_col + get_search_text().length());
- text_edit->insert_text_at_cursor(get_replace_text());
+ String replace_text = get_replace_text();
+ int search_text_len = get_search_text().length();
- text_edit->end_complex_operation();
+ 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);
+ }
- results_count = -1;
+ if (search_current()) {
+ text_editor->unfold_line(result_line);
+ text_editor->select(result_line, result_col, result_line, result_col + search_text_len);
+
+ 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);
+ if (match_to.x == selection_end.x) { // Adjust selection bounds if necessary
+ selection_end.y += replace_text.length() - search_text_len;
+ }
+ }
+ } else {
+ text_editor->insert_text_at_cursor(replace_text);
+ }
}
+ text_editor->end_complex_operation();
+ results_count = -1;
- if (!search_current()) {
- search_next();
+ 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);
+ } else {
+ text_editor->deselect();
}
}
void FindReplaceBar::_replace_all() {
- text_edit->disconnect("text_changed", callable_mp(this, &FindReplaceBar::_editor_text_changed));
+ 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_edit->cursor_get_line(), text_edit->cursor_get_column());
+ Point2i orig_cursor(text_editor->cursor_get_line(), text_editor->cursor_get_column());
Point2i prev_match = Point2(-1, -1);
- bool selection_enabled = text_edit->is_selection_active();
+ bool selection_enabled = text_editor->is_selection_active();
Point2i selection_begin, selection_end;
if (selection_enabled) {
- selection_begin = Point2i(text_edit->get_selection_from_line(), text_edit->get_selection_from_column());
- selection_end = Point2i(text_edit->get_selection_to_line(), text_edit->get_selection_to_column());
+ 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());
}
- int vsval = text_edit->get_v_scroll();
+ int vsval = text_editor->get_v_scroll();
- text_edit->cursor_set_line(0);
- text_edit->cursor_set_column(0);
+ text_editor->cursor_set_line(0);
+ text_editor->cursor_set_column(0);
String replace_text = get_replace_text();
int search_text_len = get_search_text().length();
@@ -208,11 +240,11 @@ void FindReplaceBar::_replace_all() {
replace_all_mode = true;
- text_edit->begin_complex_operation();
+ text_editor->begin_complex_operation();
if (selection_enabled && is_selection_only()) {
- text_edit->cursor_set_line(selection_begin.width);
- text_edit->cursor_set_column(selection_begin.height);
+ text_editor->cursor_set_line(selection_begin.width);
+ text_editor->cursor_set_column(selection_begin.height);
}
if (search_current()) {
do {
@@ -226,8 +258,8 @@ void FindReplaceBar::_replace_all() {
prev_match = Point2i(result_line, result_col + replace_text.length());
- text_edit->unfold_line(result_line);
- text_edit->select(result_line, result_col, result_line, match_to.y);
+ text_editor->unfold_line(result_line);
+ text_editor->select(result_line, result_col, result_line, match_to.y);
if (selection_enabled && is_selection_only()) {
if (match_from < selection_begin || match_to > selection_end) {
@@ -235,48 +267,48 @@ void FindReplaceBar::_replace_all() {
}
// Replace but adjust selection bounds.
- text_edit->insert_text_at_cursor(replace_text);
+ text_editor->insert_text_at_cursor(replace_text);
if (match_to.x == selection_end.x) {
selection_end.y += replace_text.length() - search_text_len;
}
} else {
// Just replace.
- text_edit->insert_text_at_cursor(replace_text);
+ text_editor->insert_text_at_cursor(replace_text);
}
rc++;
} while (search_next());
}
- text_edit->end_complex_operation();
+ text_editor->end_complex_operation();
replace_all_mode = false;
// Restore editor state (selection, cursor, scroll).
- text_edit->cursor_set_line(orig_cursor.x);
- text_edit->cursor_set_column(orig_cursor.y);
+ text_editor->cursor_set_line(orig_cursor.x);
+ text_editor->cursor_set_column(orig_cursor.y);
if (selection_enabled && is_selection_only()) {
// Reselect.
- text_edit->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);
} else {
- text_edit->deselect();
+ text_editor->deselect();
}
- text_edit->set_v_scroll(vsval);
+ 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->set_text(vformat(TTR("%d replaced."), rc));
- text_edit->call_deferred("connect", "text_changed", Callable(this, "_editor_text_changed"));
+ text_editor->call_deferred("connect", "text_changed", Callable(this, "_editor_text_changed"));
results_count = -1;
}
void FindReplaceBar::_get_search_from(int &r_line, int &r_col) {
- r_line = text_edit->cursor_get_line();
- r_col = text_edit->cursor_get_column();
+ r_line = text_editor->cursor_get_line();
+ r_col = text_editor->cursor_get_column();
- if (text_edit->is_selection_active() && is_selection_only()) {
+ if (text_editor->is_selection_active() && is_selection_only()) {
return;
}
@@ -293,11 +325,11 @@ void FindReplaceBar::_update_results_count() {
results_count = 0;
String searched = get_search_text();
- if (searched.empty()) {
+ if (searched.is_empty()) {
return;
}
- String full_text = text_edit->get_text();
+ String full_text = text_editor->get_text();
int from_pos = 0;
@@ -307,23 +339,24 @@ void FindReplaceBar::_update_results_count() {
break;
}
+ int pos_subsequent = pos + searched.length();
if (is_whole_words()) {
- from_pos++; // 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])) {
+ 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;
}
- if (pos + searched.length() < full_text.length() && !is_symbol(full_text[pos + searched.length()])) {
+ if (pos_subsequent < full_text.length() && !(is_symbol(full_text[pos_subsequent]) || full_text[pos_subsequent] == '\n')) {
continue;
}
}
results_count++;
- from_pos = pos + searched.length();
+ from_pos = pos_subsequent;
}
}
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();
@@ -368,7 +401,7 @@ bool FindReplaceBar::search_prev() {
int line, col;
_get_search_from(line, col);
- if (text_edit->is_selection_active()) {
+ if (text_editor->is_selection_active()) {
col--; // Skip currently selected word.
}
@@ -376,9 +409,9 @@ bool FindReplaceBar::search_prev() {
if (col < 0) {
line -= 1;
if (line < 0) {
- line = text_edit->get_line_count() - 1;
+ line = text_editor->get_line_count() - 1;
}
- col = text_edit->get_line(line).length();
+ col = text_editor->get_line(line).length();
}
return _search(flags, line, col);
@@ -409,9 +442,9 @@ bool FindReplaceBar::search_next() {
if (line == result_line && col == result_col) {
col += text.length();
- if (col > text_edit->get_line(line).length()) {
+ if (col > text_editor->get_line(line).length()) {
line += 1;
- if (line >= text_edit->get_line_count()) {
+ if (line >= text_editor->get_line_count()) {
line = 0;
}
col = 0;
@@ -423,10 +456,10 @@ bool FindReplaceBar::search_next() {
void FindReplaceBar::_hide_bar() {
if (replace_text->has_focus() || search_text->has_focus()) {
- text_edit->grab_focus();
+ text_editor->grab_focus();
}
- text_edit->set_search_text("");
+ text_editor->set_search_text("");
result_line = -1;
result_col = -1;
hide();
@@ -446,11 +479,11 @@ void FindReplaceBar::_show_search(bool p_focus_replace, bool p_show_only) {
search_text->call_deferred("grab_focus");
}
- if (text_edit->is_selection_active() && !selection_only->is_pressed()) {
- search_text->set_text(text_edit->get_selection_text());
+ if (text_editor->is_selection_active() && !selection_only->is_pressed()) {
+ search_text->set_text(text_editor->get_selection_text());
}
- 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());
@@ -480,9 +513,9 @@ void FindReplaceBar::popup_replace() {
hbc_option_replace->show();
}
- selection_only->set_pressed((text_edit->is_selection_active() && text_edit->get_selection_from_line() < text_edit->get_selection_to_line()));
+ selection_only->set_pressed((text_editor->is_selection_active() && text_editor->get_selection_from_line() < text_editor->get_selection_to_line()));
- _show_search(is_visible() || text_edit->is_selection_active());
+ _show_search(is_visible() || text_editor->is_selection_active());
}
void FindReplaceBar::_search_options_changed(bool p_pressed) {
@@ -513,7 +546,7 @@ void FindReplaceBar::_search_text_entered(const String &p_text) {
}
void FindReplaceBar::_replace_text_entered(const String &p_text) {
- if (selection_only->is_pressed() && text_edit->is_selection_active()) {
+ if (selection_only->is_pressed() && text_editor->is_selection_active()) {
_replace_all();
_hide_bar();
} else if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) {
@@ -548,10 +581,10 @@ void FindReplaceBar::set_error(const String &p_label) {
emit_signal("error", p_label);
}
-void FindReplaceBar::set_text_edit(TextEdit *p_text_edit) {
+void FindReplaceBar::set_text_edit(CodeEdit *p_text_edit) {
results_count = -1;
- text_edit = p_text_edit;
- text_edit->connect("text_changed", callable_mp(this, &FindReplaceBar::_editor_text_changed));
+ text_editor = p_text_edit;
+ text_editor->connect("text_changed", callable_mp(this, &FindReplaceBar::_editor_text_changed));
}
void FindReplaceBar::_bind_methods() {
@@ -600,12 +633,14 @@ FindReplaceBar::FindReplaceBar() {
hbc_button_search->add_child(matches_label);
matches_label->hide();
- find_prev = memnew(ToolButton);
+ find_prev = memnew(Button);
+ find_prev->set_flat(true);
hbc_button_search->add_child(find_prev);
find_prev->set_focus_mode(FOCUS_NONE);
find_prev->connect("pressed", callable_mp(this, &FindReplaceBar::search_prev));
- find_next = memnew(ToolButton);
+ find_next = memnew(Button);
+ find_next->set_flat(true);
hbc_button_search->add_child(find_next);
find_next->set_focus_mode(FOCUS_NONE);
find_next->connect("pressed", callable_mp(this, &FindReplaceBar::search_next));
@@ -657,7 +692,7 @@ FindReplaceBar::FindReplaceBar() {
// be handled too late if they weren't handled here.
void CodeTextEditor::_input(const Ref<InputEvent> &event) {
const Ref<InputEventKey> key_event = event;
- if (!key_event.is_valid() || !key_event->is_pressed()) {
+ if (!key_event.is_valid() || !key_event->is_pressed() || !text_editor->has_focus()) {
return;
}
@@ -698,17 +733,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 = text_editor->get_theme_font_size("font_size");
+ font_size *= powf(magnify_gesture->get_factor(), 0.25);
- 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("font_size"));
return;
}
@@ -746,12 +774,8 @@ 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() {
@@ -804,7 +828,14 @@ void CodeTextEditor::_complete_request() {
}
for (List<ScriptCodeCompletionOption>::Element *E = entries.front(); E; E = E->next()) {
- E->get().icon = _get_completion_icon(E->get());
+ 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;
+ }
}
text_editor->code_complete(entries, forced);
}
@@ -844,7 +875,7 @@ Ref<Texture2D> CodeTextEditor::_get_completion_icon(const ScriptCodeCompletionOp
tex = get_theme_icon("MemberMethod", "EditorIcons");
break;
case ScriptCodeCompletionOption::KIND_PLAIN_TEXT:
- tex = get_theme_icon("CubeMesh", "EditorIcons");
+ tex = get_theme_icon("BoxMesh", "EditorIcons");
break;
default:
tex = get_theme_icon("String", "EditorIcons");
@@ -860,24 +891,22 @@ void CodeTextEditor::_font_resize_timeout() {
}
bool CodeTextEditor::_add_font_size(int p_delta) {
- Ref<DynamicFont> font = text_editor->get_theme_font("font");
-
- if (font.is_valid()) {
- int new_size = CLAMP(font->get_size() + p_delta, 8 * EDSCALE, 96 * EDSCALE);
+ int old_size = text_editor->get_theme_font_size("font_size");
+ int new_size = CLAMP(old_size + p_delta, 8 * EDSCALE, 96 * EDSCALE);
- 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;
- } else {
- return false;
+ 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);
}
+
+ return true;
}
void CodeTextEditor::update_editor_settings() {
- text_editor->set_syntax_coloring(EditorSettings::get_singleton()->get("text_editor/highlighting/syntax_highlighting"));
+ 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"));
@@ -889,11 +918,9 @@ void CodeTextEditor::update_editor_settings() {
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_show_line_numbers(EditorSettings::get_singleton()->get("text_editor/appearance/show_line_numbers"));
+ 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_bookmark_gutter_enabled(EditorSettings::get_singleton()->get("text_editor/appearance/show_bookmark_gutter"));
- text_editor->set_breakpoint_gutter_enabled(EditorSettings::get_singleton()->get("text_editor/appearance/show_breakpoint_gutter"));
- text_editor->set_draw_info_gutter(EditorSettings::get_singleton()->get("text_editor/appearance/show_info_gutter"));
+ 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"));
@@ -1097,6 +1124,7 @@ void CodeTextEditor::move_lines_up() {
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();
+ int cursor_line = text_editor->cursor_get_line();
for (int i = from_line; i <= to_line; i++) {
int line_id = i;
@@ -1114,7 +1142,9 @@ void CodeTextEditor::move_lines_up() {
}
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);
+ text_editor->cursor_set_line(cursor_line_up);
} else {
int line_id = text_editor->cursor_get_line();
int next_id = line_id - 1;
@@ -1140,6 +1170,7 @@ void CodeTextEditor::move_lines_down() {
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();
+ int cursor_line = text_editor->cursor_get_line();
for (int i = to_line; i >= from_line; i--) {
int line_id = i;
@@ -1157,7 +1188,9 @@ void CodeTextEditor::move_lines_down() {
}
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);
+ text_editor->cursor_set_line(cursor_line_down);
} else {
int line_id = text_editor->cursor_get_line();
int next_id = line_id + 1;
@@ -1276,7 +1309,7 @@ void CodeTextEditor::toggle_inline_comment(const String &delimiter) {
for (int i = begin; i <= end; i++) {
String line_text = text_editor->get_line(i);
- if (line_text.strip_edges().empty()) {
+ if (line_text.strip_edges().is_empty()) {
line_text = delimiter;
} else {
if (is_commented) {
@@ -1347,11 +1380,11 @@ void CodeTextEditor::goto_line_centered(int p_line) {
}
void CodeTextEditor::set_executing_line(int p_line) {
- text_editor->set_executing_line(p_line);
+ text_editor->set_line_as_executing(p_line, true);
}
void CodeTextEditor::clear_executing_line() {
- text_editor->clear_executing_line();
+ text_editor->clear_executing_lines();
}
Variant CodeTextEditor::get_edit_state() {
@@ -1362,8 +1395,8 @@ Variant CodeTextEditor::get_edit_state() {
state["column"] = text_editor->cursor_get_column();
state["row"] = text_editor->cursor_get_line();
- state["selection"] = get_text_edit()->is_selection_active();
- if (get_text_edit()->is_selection_active()) {
+ 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();
@@ -1371,14 +1404,11 @@ Variant CodeTextEditor::get_edit_state() {
}
state["folded_lines"] = text_editor->get_folded_lines();
- state["breakpoints"] = text_editor->get_breakpoints_array();
- state["bookmarks"] = text_editor->get_bookmarks_array();
+ state["breakpoints"] = text_editor->get_breakpointed_lines();
+ state["bookmarks"] = text_editor->get_bookmarked_lines();
- state["syntax_highlighter"] = TTR("Standard");
- SyntaxHighlighter *syntax_highlighter = text_editor->_get_syntax_highlighting();
- if (syntax_highlighter) {
- state["syntax_highlighter"] = syntax_highlighter->get_name();
- }
+ Ref<EditorSyntaxHighlighter> syntax_highlighter = text_editor->get_syntax_highlighter();
+ state["syntax_highlighter"] = syntax_highlighter->_get_name();
return state;
}
@@ -1413,11 +1443,9 @@ void CodeTextEditor::set_edit_state(const Variant &p_state) {
if (state.has("bookmarks")) {
Array bookmarks = state["bookmarks"];
for (int i = 0; i < bookmarks.size(); i++) {
- text_editor->set_line_as_bookmark(bookmarks[i], true);
+ text_editor->set_line_as_bookmarked(bookmarks[i], true);
}
}
-
- text_editor->grab_focus();
}
void CodeTextEditor::set_error(const String &p_error) {
@@ -1444,17 +1472,22 @@ void CodeTextEditor::goto_error() {
void CodeTextEditor::_update_font() {
text_editor->add_theme_font_override("font", get_theme_font("source", "EditorFonts"));
+ text_editor->add_theme_font_size_override("font_size", get_theme_font_size("source_size", "EditorFonts"));
error->add_theme_font_override("font", get_theme_font("status_source", "EditorFonts"));
+ error->add_theme_font_size_override("font_size", get_theme_font_size("status_source_size", "EditorFonts"));
error->add_theme_color_override("font_color", get_theme_color("error_color", "Editor"));
Ref<Font> status_bar_font = get_theme_font("status_source", "EditorFonts");
+ int status_bar_font_size = get_theme_font_size("status_source_size", "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);
}
}
}
@@ -1464,6 +1497,31 @@ void CodeTextEditor::_on_settings_change() {
font_size = EditorSettings::get_singleton()->get("interface/editor/code_font_size");
+ int ot_mode = EditorSettings::get_singleton()->get("interface/editor/code_font_contextual_ligatures");
+ switch (ot_mode) {
+ case 1: { // Disable ligatures.
+ text_editor->clear_opentype_features();
+ text_editor->set_opentype_feature("calt", 0);
+ } break;
+ case 2: { // Custom.
+ text_editor->clear_opentype_features();
+ Vector<String> subtag = String(EditorSettings::get_singleton()->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) {
+ text_editor->set_opentype_feature(subtag_a[0], subtag_a[1].to_int());
+ } else if (subtag_a.size() == 1) {
+ text_editor->set_opentype_feature(subtag_a[0], 1);
+ }
+ }
+ } break;
+ default: { // Default.
+ text_editor->clear_opentype_features();
+ text_editor->set_opentype_feature("calt", 1);
+ } break;
+ }
+
// Auto brace completion.
text_editor->set_auto_brace_completion(
EDITOR_GET("text_editor/completion/auto_brace_complete"));
@@ -1505,13 +1563,17 @@ void CodeTextEditor::_set_show_warnings_panel(bool 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"));
+ if (is_layout_rtl()) {
+ toggle_scripts_button->set_icon(ScriptEditor::get_singleton()->toggle_scripts_panel() ? get_theme_icon("Forward", "EditorIcons") : get_theme_icon("Back", "EditorIcons"));
+ } else {
+ toggle_scripts_button->set_icon(ScriptEditor::get_singleton()->toggle_scripts_panel() ? get_theme_icon("Back", "EditorIcons") : get_theme_icon("Forward", "EditorIcons"));
+ }
}
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) {
- emit_signal("error_pressed");
+ goto_error();
}
}
@@ -1553,27 +1615,26 @@ void CodeTextEditor::set_warning_nb(int p_warning_nb) {
void CodeTextEditor::toggle_bookmark() {
int line = text_editor->cursor_get_line();
- text_editor->set_line_as_bookmark(line, !text_editor->is_line_set_as_bookmark(line));
+ text_editor->set_line_as_bookmarked(line, !text_editor->is_line_bookmarked(line));
}
void CodeTextEditor::goto_next_bookmark() {
- List<int> bmarks;
- text_editor->get_bookmarks(&bmarks);
+ Array bmarks = text_editor->get_bookmarked_lines();
if (bmarks.size() <= 0) {
return;
}
int line = text_editor->cursor_get_line();
- if (line >= bmarks[bmarks.size() - 1]) {
+ 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();
} else {
- for (List<int>::Element *E = bmarks.front(); E; E = E->next()) {
- int bline = E->get();
- if (bline > line) {
- text_editor->unfold_line(bline);
- text_editor->cursor_set_line(bline);
+ 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();
return;
}
@@ -1582,23 +1643,22 @@ void CodeTextEditor::goto_next_bookmark() {
}
void CodeTextEditor::goto_prev_bookmark() {
- List<int> bmarks;
- text_editor->get_bookmarks(&bmarks);
+ Array bmarks = text_editor->get_bookmarked_lines();
if (bmarks.size() <= 0) {
return;
}
int line = text_editor->cursor_get_line();
- if (line <= bmarks[0]) {
+ 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();
} else {
- for (List<int>::Element *E = bmarks.back(); E; E = E->prev()) {
- int bline = E->get();
- if (bline < line) {
- text_editor->unfold_line(bline);
- text_editor->cursor_set_line(bline);
+ for (int i = bmarks.size(); 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();
return;
}
@@ -1607,12 +1667,7 @@ void CodeTextEditor::goto_prev_bookmark() {
}
void CodeTextEditor::remove_all_bookmarks() {
- List<int> bmarks;
- text_editor->get_bookmarks(&bmarks);
-
- for (List<int>::Element *E = bmarks.front(); E; E = E->next()) {
- text_editor->set_line_as_bookmark(E->get(), false);
- }
+ text_editor->clear_bookmarked_lines();
}
void CodeTextEditor::_bind_methods() {
@@ -1621,7 +1676,6 @@ void CodeTextEditor::_bind_methods() {
ADD_SIGNAL(MethodInfo("validate_script"));
ADD_SIGNAL(MethodInfo("load_theme_settings"));
ADD_SIGNAL(MethodInfo("show_warnings_panel"));
- ADD_SIGNAL(MethodInfo("error_pressed"));
}
void CodeTextEditor::set_code_complete_func(CodeTextEditorCodeCompleteFunc p_code_complete_func, void *p_ud) {
@@ -1634,7 +1688,11 @@ 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"));
+ if (is_layout_rtl()) {
+ toggle_scripts_button->set_icon(ScriptEditor::get_singleton()->is_scripts_panel_toggled() ? get_theme_icon("Forward", "EditorIcons") : get_theme_icon("Back", "EditorIcons"));
+ } else {
+ 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() + ")");
}
@@ -1644,10 +1702,35 @@ CodeTextEditor::CodeTextEditor() {
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);
- text_editor = memnew(TextEdit);
+ text_editor = memnew(CodeEdit);
add_child(text_editor);
text_editor->set_v_size_flags(SIZE_EXPAND_FILL);
+ int ot_mode = EditorSettings::get_singleton()->get("interface/editor/code_font_contextual_ligatures");
+ switch (ot_mode) {
+ case 1: { // Disable ligatures.
+ text_editor->clear_opentype_features();
+ text_editor->set_opentype_feature("calt", 0);
+ } break;
+ case 2: { // Custom.
+ text_editor->clear_opentype_features();
+ Vector<String> subtag = String(EditorSettings::get_singleton()->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) {
+ text_editor->set_opentype_feature(subtag_a[0], subtag_a[1].to_int());
+ } else if (subtag_a.size() == 1) {
+ text_editor->set_opentype_feature(subtag_a[0], 1);
+ }
+ }
+ } break;
+ default: { // Default.
+ text_editor->clear_opentype_features();
+ text_editor->set_opentype_feature("calt", 1);
+ } break;
+ }
+
// 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);
@@ -1656,7 +1739,7 @@ CodeTextEditor::CodeTextEditor() {
find_replace_bar->set_text_edit(text_editor);
- text_editor->set_show_line_numbers(true);
+ text_editor->set_draw_line_numbers(true);
text_editor->set_brace_matching(true);
text_editor->set_auto_indent(true);
@@ -1678,7 +1761,8 @@ CodeTextEditor::CodeTextEditor() {
error_line = 0;
error_column = 0;
- toggle_scripts_button = memnew(ToolButton);
+ toggle_scripts_button = memnew(Button);
+ toggle_scripts_button->set_flat(true);
toggle_scripts_button->connect("pressed", callable_mp(this, &CodeTextEditor::_toggle_scripts_pressed));
status_bar->add_child(toggle_scripts_button);
toggle_scripts_button->hide();
@@ -1698,7 +1782,8 @@ CodeTextEditor::CodeTextEditor() {
find_replace_bar->connect("error", callable_mp(error, &Label::set_text));
// Warnings
- warning_button = memnew(ToolButton);
+ warning_button = memnew(Button);
+ warning_button->set_flat(true);
status_bar->add_child(warning_button);
warning_button->set_v_size_flags(SIZE_EXPAND | SIZE_SHRINK_CENTER);
warning_button->set_default_cursor_shape(CURSOR_POINTING_HAND);
@@ -1714,6 +1799,7 @@ CodeTextEditor::CodeTextEditor() {
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->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size("status_source_size", "EditorFonts"));
warning_count_label->connect("gui_input", callable_mp(this, &CodeTextEditor::_warning_label_gui_input));
is_warnings_panel_opened = false;
@@ -1724,6 +1810,7 @@ CodeTextEditor::CodeTextEditor() {
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->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size("status_source_size", "EditorFonts"));
line_and_col_txt->set_tooltip(TTR("Line and column numbers."));
line_and_col_txt->set_mouse_filter(MOUSE_FILTER_STOP);
@@ -1737,6 +1824,7 @@ CodeTextEditor::CodeTextEditor() {
cs.push_back("(");
cs.push_back("=");
cs.push_back("$");
+ cs.push_back("@");
text_editor->set_completion(true, cs);
idle->connect("timeout", callable_mp(this, &CodeTextEditor::_text_changed_idle_timeout));