From d5dcaee4c5b41faca64f02888b152f7f05c4a20b Mon Sep 17 00:00:00 2001 From: Paulb23 Date: Thu, 8 Jul 2021 18:35:56 +0100 Subject: Cleanup and rename caret operations --- editor/plugins/text_editor.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'editor/plugins/text_editor.cpp') diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp index faf287b9bd..6eea8ae227 100644 --- a/editor/plugins/text_editor.cpp +++ b/editor/plugins/text_editor.cpp @@ -132,14 +132,14 @@ void TextEditor::reload_text() { ERR_FAIL_COND(text_file.is_null()); CodeEdit *te = code_editor->get_text_editor(); - int column = te->cursor_get_column(); - int row = te->cursor_get_line(); + int column = te->get_caret_column(); + int row = te->get_caret_line(); int h = te->get_h_scroll(); int v = te->get_v_scroll(); te->set_text(text_file->get_text()); - te->cursor_set_line(row); - te->cursor_set_column(column); + te->set_caret_line(row); + te->set_caret_column(column); te->set_h_scroll(h); te->set_v_scroll(v); @@ -332,7 +332,7 @@ void TextEditor::_edit_option(int p_op) { code_editor->duplicate_selection(); } break; case EDIT_TOGGLE_FOLD_LINE: { - tx->toggle_foldable_line(tx->cursor_get_line()); + tx->toggle_foldable_line(tx->get_caret_line()); tx->update(); } break; case EDIT_FOLD_ALL_LINES: { @@ -431,11 +431,11 @@ void TextEditor::_text_edit_gui_input(const Ref &ev) { CodeEdit *tx = code_editor->get_text_editor(); tx->_get_mouse_pos(mb->get_global_position() - tx->get_global_position(), row, col); - tx->set_right_click_moves_caret(EditorSettings::get_singleton()->get("text_editor/cursor/right_click_moves_caret")); + tx->set_move_caret_on_right_click_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/right_click_moves_caret")); bool can_fold = tx->can_fold_line(row); bool is_folded = tx->is_line_folded(row); - if (tx->is_right_click_moving_caret()) { + if (tx->is_move_caret_on_right_click_enabled()) { if (tx->is_selection_active()) { int from_line = tx->get_selection_from_line(); int to_line = tx->get_selection_to_line(); @@ -448,8 +448,8 @@ void TextEditor::_text_edit_gui_input(const Ref &ev) { } } if (!tx->is_selection_active()) { - tx->cursor_set_line(row, true, false); - tx->cursor_set_column(col); + tx->set_caret_line(row, true, false); + tx->set_caret_column(col); } } @@ -460,10 +460,11 @@ void TextEditor::_text_edit_gui_input(const Ref &ev) { } Ref k = ev; - if (k.is_valid() && k->is_pressed() && k->get_keycode() == KEY_MENU) { + if (k.is_valid() && k->is_pressed() && k->is_action("ui_menu", true)) { CodeEdit *tx = code_editor->get_text_editor(); - int line = tx->cursor_get_line(); - _make_context_menu(tx->is_selection_active(), tx->can_fold_line(line), tx->is_line_folded(line), (get_global_transform().inverse() * tx->get_global_transform()).xform(tx->_get_cursor_pixel_pos())); + int line = tx->get_caret_line(); + tx->adjust_viewport_to_caret(); + _make_context_menu(tx->is_selection_active(), tx->can_fold_line(line), tx->is_line_folded(line), (get_global_transform().inverse() * tx->get_global_transform()).xform(tx->get_caret_draw_pos())); context_menu->grab_focus(); } } -- cgit v1.2.3 From 9ec3e7f3d7ae7f9eaf5a1de29346c5e10b3af6f9 Mon Sep 17 00:00:00 2001 From: Paulb23 Date: Fri, 9 Jul 2021 12:42:55 +0100 Subject: Cleanup TextEdit selection methods --- editor/plugins/text_editor.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'editor/plugins/text_editor.cpp') diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp index 6eea8ae227..4e90399433 100644 --- a/editor/plugins/text_editor.cpp +++ b/editor/plugins/text_editor.cpp @@ -374,14 +374,14 @@ void TextEditor::_edit_option(int p_op) { code_editor->get_find_replace_bar()->popup_replace(); } break; case SEARCH_IN_FILES: { - String selected_text = code_editor->get_text_editor()->get_selection_text(); + String selected_text = code_editor->get_text_editor()->get_selected_text(); // Yep, because it doesn't make sense to instance this dialog for every single script open... // So this will be delegated to the ScriptEditor. emit_signal(SNAME("search_in_files_requested"), selected_text); } break; case REPLACE_IN_FILES: { - String selected_text = code_editor->get_text_editor()->get_selection_text(); + String selected_text = code_editor->get_text_editor()->get_selected_text(); emit_signal(SNAME("replace_in_files_requested"), selected_text); } break; @@ -436,7 +436,7 @@ void TextEditor::_text_edit_gui_input(const Ref &ev) { bool is_folded = tx->is_line_folded(row); if (tx->is_move_caret_on_right_click_enabled()) { - if (tx->is_selection_active()) { + if (tx->has_selection()) { int from_line = tx->get_selection_from_line(); int to_line = tx->get_selection_to_line(); int from_column = tx->get_selection_from_column(); @@ -447,14 +447,14 @@ void TextEditor::_text_edit_gui_input(const Ref &ev) { tx->deselect(); } } - if (!tx->is_selection_active()) { + if (!tx->has_selection()) { tx->set_caret_line(row, true, false); tx->set_caret_column(col); } } if (!mb->is_pressed()) { - _make_context_menu(tx->is_selection_active(), can_fold, is_folded, get_local_mouse_position()); + _make_context_menu(tx->has_selection(), can_fold, is_folded, get_local_mouse_position()); } } } @@ -464,7 +464,7 @@ void TextEditor::_text_edit_gui_input(const Ref &ev) { CodeEdit *tx = code_editor->get_text_editor(); int line = tx->get_caret_line(); tx->adjust_viewport_to_caret(); - _make_context_menu(tx->is_selection_active(), tx->can_fold_line(line), tx->is_line_folded(line), (get_global_transform().inverse() * tx->get_global_transform()).xform(tx->get_caret_draw_pos())); + _make_context_menu(tx->has_selection(), tx->can_fold_line(line), tx->is_line_folded(line), (get_global_transform().inverse() * tx->get_global_transform()).xform(tx->get_caret_draw_pos())); context_menu->grab_focus(); } } -- cgit v1.2.3 From b70001131498d9487cc131d0ba27fff1abab99e8 Mon Sep 17 00:00:00 2001 From: Paulb23 Date: Fri, 9 Jul 2021 13:07:10 +0100 Subject: Protect internal CodeEdit --> TextEdit API --- editor/plugins/text_editor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'editor/plugins/text_editor.cpp') diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp index 4e90399433..f38bb6e996 100644 --- a/editor/plugins/text_editor.cpp +++ b/editor/plugins/text_editor.cpp @@ -340,7 +340,7 @@ void TextEditor::_edit_option(int p_op) { tx->update(); } break; case EDIT_UNFOLD_ALL_LINES: { - tx->unhide_all_lines(); + tx->unfold_all_lines(); tx->update(); } break; case EDIT_TRIM_TRAILING_WHITESAPCE: { -- cgit v1.2.3 From ae4dcb89182c44c923f8aac29855bebc701a237f Mon Sep 17 00:00:00 2001 From: Paulb23 Date: Sat, 10 Jul 2021 11:41:38 +0100 Subject: Cleanup and bind remaing methods in TextEdit --- editor/plugins/text_editor.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'editor/plugins/text_editor.cpp') diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp index f38bb6e996..cfccf90499 100644 --- a/editor/plugins/text_editor.cpp +++ b/editor/plugins/text_editor.cpp @@ -427,9 +427,11 @@ void TextEditor::_text_edit_gui_input(const Ref &ev) { if (mb.is_valid()) { if (mb->get_button_index() == MOUSE_BUTTON_RIGHT) { - int col, row; CodeEdit *tx = code_editor->get_text_editor(); - tx->_get_mouse_pos(mb->get_global_position() - tx->get_global_position(), row, col); + + Point2i pos = tx->get_line_column_at_pos(mb->get_global_position() - tx->get_global_position()); + int row = pos.y; + int col = pos.x; tx->set_move_caret_on_right_click_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/right_click_moves_caret")); bool can_fold = tx->can_fold_line(row); -- cgit v1.2.3