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.cpp104
1 files changed, 49 insertions, 55 deletions
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp
index e05ace53da..ddd702fc6c 100644
--- a/editor/code_editor.cpp
+++ b/editor/code_editor.cpp
@@ -122,7 +122,7 @@ void FindReplaceBar::_unhandled_input(const Ref<InputEvent> &p_event) {
bool accepted = true;
- switch (k->get_scancode()) {
+ switch (k->get_keycode()) {
case KEY_ESCAPE: {
@@ -200,7 +200,7 @@ void FindReplaceBar::_replace() {
void FindReplaceBar::_replace_all() {
- text_edit->disconnect("text_changed", this, "_editor_text_changed");
+ text_edit->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 prev_match = Point2(-1, -1);
@@ -280,7 +280,7 @@ void FindReplaceBar::_replace_all() {
matches_label->add_color_override("font_color", rc > 0 ? get_color("font_color", "Label") : get_color("error_color", "Editor"));
matches_label->set_text(vformat(TTR("%d replaced."), rc));
- text_edit->call_deferred("connect", "text_changed", this, "_editor_text_changed");
+ text_edit->call_deferred("connect", "text_changed", Callable(this, "_editor_text_changed"));
results_count = -1;
}
@@ -517,6 +517,11 @@ void FindReplaceBar::_replace_text_entered(const String &p_text) {
if (selection_only->is_pressed() && text_edit->is_selection_active()) {
_replace_all();
_hide_bar();
+ } else if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) {
+ _replace();
+ search_prev();
+ } else {
+ _replace();
}
}
@@ -554,24 +559,14 @@ void FindReplaceBar::set_text_edit(TextEdit *p_text_edit) {
results_count = -1;
text_edit = p_text_edit;
- text_edit->connect("text_changed", this, "_editor_text_changed");
+ text_edit->connect("text_changed", callable_mp(this, &FindReplaceBar::_editor_text_changed));
}
void FindReplaceBar::_bind_methods() {
ClassDB::bind_method("_unhandled_input", &FindReplaceBar::_unhandled_input);
- ClassDB::bind_method("_editor_text_changed", &FindReplaceBar::_editor_text_changed);
- ClassDB::bind_method("_search_text_changed", &FindReplaceBar::_search_text_changed);
- ClassDB::bind_method("_search_text_entered", &FindReplaceBar::_search_text_entered);
- ClassDB::bind_method("_replace_text_entered", &FindReplaceBar::_replace_text_entered);
ClassDB::bind_method("_search_current", &FindReplaceBar::search_current);
- ClassDB::bind_method("_search_next", &FindReplaceBar::search_next);
- ClassDB::bind_method("_search_prev", &FindReplaceBar::search_prev);
- ClassDB::bind_method("_replace_pressed", &FindReplaceBar::_replace);
- ClassDB::bind_method("_replace_all_pressed", &FindReplaceBar::_replace_all);
- ClassDB::bind_method("_search_options_changed", &FindReplaceBar::_search_options_changed);
- ClassDB::bind_method("_hide_pressed", &FindReplaceBar::_hide_bar);
ADD_SIGNAL(MethodInfo("search"));
ADD_SIGNAL(MethodInfo("error"));
@@ -608,8 +603,8 @@ FindReplaceBar::FindReplaceBar() {
search_text = memnew(LineEdit);
vbc_lineedit->add_child(search_text);
search_text->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
- search_text->connect("text_changed", this, "_search_text_changed");
- search_text->connect("text_entered", this, "_search_text_entered");
+ search_text->connect("text_changed", callable_mp(this, &FindReplaceBar::_search_text_changed));
+ search_text->connect("text_entered", callable_mp(this, &FindReplaceBar::_search_text_entered));
matches_label = memnew(Label);
hbc_button_search->add_child(matches_label);
@@ -618,51 +613,51 @@ FindReplaceBar::FindReplaceBar() {
find_prev = memnew(ToolButton);
hbc_button_search->add_child(find_prev);
find_prev->set_focus_mode(FOCUS_NONE);
- find_prev->connect("pressed", this, "_search_prev");
+ find_prev->connect("pressed", callable_mp(this, &FindReplaceBar::search_prev));
find_next = memnew(ToolButton);
hbc_button_search->add_child(find_next);
find_next->set_focus_mode(FOCUS_NONE);
- find_next->connect("pressed", this, "_search_next");
+ find_next->connect("pressed", callable_mp(this, &FindReplaceBar::search_next));
case_sensitive = memnew(CheckBox);
hbc_option_search->add_child(case_sensitive);
case_sensitive->set_text(TTR("Match Case"));
case_sensitive->set_focus_mode(FOCUS_NONE);
- case_sensitive->connect("toggled", this, "_search_options_changed");
+ case_sensitive->connect("toggled", callable_mp(this, &FindReplaceBar::_search_options_changed));
whole_words = memnew(CheckBox);
hbc_option_search->add_child(whole_words);
whole_words->set_text(TTR("Whole Words"));
whole_words->set_focus_mode(FOCUS_NONE);
- whole_words->connect("toggled", this, "_search_options_changed");
+ whole_words->connect("toggled", callable_mp(this, &FindReplaceBar::_search_options_changed));
// replace toolbar
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", this, "_replace_text_entered");
+ replace_text->connect("text_entered", callable_mp(this, &FindReplaceBar::_replace_text_entered));
replace = memnew(Button);
hbc_button_replace->add_child(replace);
replace->set_text(TTR("Replace"));
- replace->connect("pressed", this, "_replace_pressed");
+ replace->connect("pressed", callable_mp(this, &FindReplaceBar::_replace));
replace_all = memnew(Button);
hbc_button_replace->add_child(replace_all);
replace_all->set_text(TTR("Replace All"));
- replace_all->connect("pressed", this, "_replace_all_pressed");
+ replace_all->connect("pressed", callable_mp(this, &FindReplaceBar::_replace_all));
selection_only = memnew(CheckBox);
hbc_option_replace->add_child(selection_only);
selection_only->set_text(TTR("Selection Only"));
selection_only->set_focus_mode(FOCUS_NONE);
- selection_only->connect("toggled", this, "_search_options_changed");
+ selection_only->connect("toggled", callable_mp(this, &FindReplaceBar::_search_options_changed));
hide_button = memnew(TextureButton);
add_child(hide_button);
hide_button->set_focus_mode(FOCUS_NONE);
- hide_button->connect("pressed", this, "_hide_pressed");
+ hide_button->connect("pressed", callable_mp(this, &FindReplaceBar::_hide_bar));
hide_button->set_v_size_flags(SIZE_SHRINK_CENTER);
}
@@ -686,6 +681,16 @@ void CodeTextEditor::_input(const Ref<InputEvent> &event) {
accept_event();
return;
}
+ if (ED_IS_SHORTCUT("script_text_editor/delete_line", key_event)) {
+ delete_lines();
+ accept_event();
+ return;
+ }
+ if (ED_IS_SHORTCUT("script_text_editor/clone_down", key_event)) {
+ clone_lines_down();
+ accept_event();
+ return;
+ }
}
void CodeTextEditor::_text_editor_gui_input(const Ref<InputEvent> &p_event) {
@@ -819,8 +824,8 @@ void CodeTextEditor::_complete_request() {
text_editor->code_complete(entries, forced);
}
-Ref<Texture> CodeTextEditor::_get_completion_icon(const ScriptCodeCompletionOption &p_option) {
- Ref<Texture> tex;
+Ref<Texture2D> CodeTextEditor::_get_completion_icon(const ScriptCodeCompletionOption &p_option) {
+ Ref<Texture2D> tex;
switch (p_option.kind) {
case ScriptCodeCompletionOption::KIND_CLASS: {
if (has_icon(p_option.display, "EditorIcons")) {
@@ -910,8 +915,9 @@ void CodeTextEditor::update_editor_settings() {
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_guideline(EditorSettings::get_singleton()->get("text_editor/appearance/show_line_length_guideline"));
- text_editor->set_line_length_guideline_column(EditorSettings::get_singleton()->get("text_editor/appearance/line_length_guideline_column"));
+ 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"));
@@ -1251,7 +1257,7 @@ void CodeTextEditor::clone_lines_down() {
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, 2 * to_column - from_column);
+ text_editor->select(to_line, to_column, 2 * to_line - from_line, to_line == from_line ? 2 * to_column - from_column : to_column);
}
text_editor->end_complex_operation();
@@ -1627,18 +1633,6 @@ void CodeTextEditor::remove_all_bookmarks() {
void CodeTextEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("_input"), &CodeTextEditor::_input);
- ClassDB::bind_method("_text_editor_gui_input", &CodeTextEditor::_text_editor_gui_input);
- ClassDB::bind_method("_line_col_changed", &CodeTextEditor::_line_col_changed);
- ClassDB::bind_method("_text_changed", &CodeTextEditor::_text_changed);
- ClassDB::bind_method("_on_settings_change", &CodeTextEditor::_on_settings_change);
- ClassDB::bind_method("_text_changed_idle_timeout", &CodeTextEditor::_text_changed_idle_timeout);
- ClassDB::bind_method("_code_complete_timer_timeout", &CodeTextEditor::_code_complete_timer_timeout);
- ClassDB::bind_method("_complete_request", &CodeTextEditor::_complete_request);
- ClassDB::bind_method("_font_resize_timeout", &CodeTextEditor::_font_resize_timeout);
- ClassDB::bind_method("_error_pressed", &CodeTextEditor::_error_pressed);
- ClassDB::bind_method("_toggle_scripts_pressed", &CodeTextEditor::_toggle_scripts_pressed);
- ClassDB::bind_method("_warning_button_pressed", &CodeTextEditor::_warning_button_pressed);
- ClassDB::bind_method("_warning_label_gui_input", &CodeTextEditor::_warning_label_gui_input);
ADD_SIGNAL(MethodInfo("validate_script"));
ADD_SIGNAL(MethodInfo("load_theme_settings"));
@@ -1702,7 +1696,7 @@ CodeTextEditor::CodeTextEditor() {
error_column = 0;
toggle_scripts_button = memnew(ToolButton);
- toggle_scripts_button->connect("pressed", this, "_toggle_scripts_pressed");
+ toggle_scripts_button->connect("pressed", callable_mp(this, &CodeTextEditor::_toggle_scripts_pressed));
status_bar->add_child(toggle_scripts_button);
toggle_scripts_button->hide();
@@ -1717,15 +1711,15 @@ CodeTextEditor::CodeTextEditor() {
scroll->add_child(error);
error->set_v_size_flags(SIZE_EXPAND | SIZE_SHRINK_CENTER);
error->set_mouse_filter(MOUSE_FILTER_STOP);
- error->connect("gui_input", this, "_error_pressed");
- find_replace_bar->connect("error", error, "set_text");
+ error->connect("gui_input", callable_mp(this, &CodeTextEditor::_error_pressed));
+ find_replace_bar->connect("error", callable_mp(error, &Label::set_text));
// Warnings
warning_button = memnew(ToolButton);
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);
- warning_button->connect("pressed", this, "_warning_button_pressed");
+ warning_button->connect("pressed", callable_mp(this, &CodeTextEditor::_warning_button_pressed));
warning_button->set_tooltip(TTR("Warnings"));
warning_count_label = memnew(Label);
@@ -1737,7 +1731,7 @@ CodeTextEditor::CodeTextEditor() {
warning_count_label->set_tooltip(TTR("Warnings"));
warning_count_label->add_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_color("warning_color", "Editor"));
warning_count_label->add_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_font("status_source", "EditorFonts"));
- warning_count_label->connect("gui_input", this, "_warning_label_gui_input");
+ warning_count_label->connect("gui_input", callable_mp(this, &CodeTextEditor::_warning_label_gui_input));
is_warnings_panel_opened = false;
set_warning_nb(0);
@@ -1750,10 +1744,10 @@ CodeTextEditor::CodeTextEditor() {
line_and_col_txt->set_tooltip(TTR("Line and column numbers."));
line_and_col_txt->set_mouse_filter(MOUSE_FILTER_STOP);
- text_editor->connect("gui_input", this, "_text_editor_gui_input");
- text_editor->connect("cursor_changed", this, "_line_col_changed");
- text_editor->connect("text_changed", this, "_text_changed");
- text_editor->connect("request_completion", this, "_complete_request");
+ 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("text_changed", callable_mp(this, &CodeTextEditor::_text_changed));
+ text_editor->connect("request_completion", callable_mp(this, &CodeTextEditor::_complete_request));
Vector<String> cs;
cs.push_back(".");
cs.push_back(",");
@@ -1761,9 +1755,9 @@ CodeTextEditor::CodeTextEditor() {
cs.push_back("=");
cs.push_back("$");
text_editor->set_completion(true, cs);
- idle->connect("timeout", this, "_text_changed_idle_timeout");
+ idle->connect("timeout", callable_mp(this, &CodeTextEditor::_text_changed_idle_timeout));
- code_complete_timer->connect("timeout", this, "_code_complete_timer_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");
@@ -1771,7 +1765,7 @@ CodeTextEditor::CodeTextEditor() {
add_child(font_resize_timer);
font_resize_timer->set_one_shot(true);
font_resize_timer->set_wait_time(0.07);
- font_resize_timer->connect("timeout", this, "_font_resize_timeout");
+ font_resize_timer->connect("timeout", callable_mp(this, &CodeTextEditor::_font_resize_timeout));
- EditorSettings::get_singleton()->connect("settings_changed", this, "_on_settings_change");
+ EditorSettings::get_singleton()->connect("settings_changed", callable_mp(this, &CodeTextEditor::_on_settings_change));
}