summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
authorAlfred Reinold Baudisch <alfred@alfredbaudisch.com>2022-10-31 16:55:47 +0100
committerAlfred Reinold Baudisch <alfred@alfredbaudisch.com>2022-10-31 17:44:47 +0100
commitfcff9787638e73eac0802ff6abdba6061a569d81 (patch)
tree6bca261a97053ef276ca2bfa337800eb8a4973f4 /scene/gui
parent2ccd827453fe1a48b6b59b91944e3a202c364b97 (diff)
Shortcut and Bind to Remove Secondary Carets
Adds the bind `ui_text_remove_secondary_carets` to TextEdit, with ESC as the default shortcut. When the bind is performed, if the TextEdit has multiple carets, `remove_secondary_carets` is called and secondary carets are removed. This is useful when multiple selects are performed with `add_select_for_next_occurrence` #67644 or when multiple multiple carets are manually added, then it's possible to go back to a single caret with a shortcut. Closes #67991
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/text_edit.cpp9
-rw-r--r--scene/gui/text_edit.h1
2 files changed, 10 insertions, 0 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 144aa2a1ef..cc9fc99b9c 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -2067,6 +2067,11 @@ void TextEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
accept_event();
return;
}
+ if (k->is_action("ui_text_remove_secondary_carets", true) && _should_remove_secondary_carets()) {
+ remove_secondary_carets();
+ accept_event();
+ return;
+ }
if (k->is_action("ui_cut", true)) {
cut();
accept_event();
@@ -2819,6 +2824,10 @@ void TextEdit::_move_caret_document_end(bool p_select) {
}
}
+bool TextEdit::_should_remove_secondary_carets() {
+ return carets.size() > 1;
+}
+
void TextEdit::_get_above_below_caret_line_column(int p_old_line, int p_old_wrap_index, int p_old_column, bool p_below, int &p_new_line, int &p_new_column, int p_last_fit_x) const {
if (p_last_fit_x == -1) {
p_last_fit_x = _get_column_x_offset_for_line(p_old_column, p_old_line, p_old_column);
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index 935f2a7ce8..263a36aba8 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -597,6 +597,7 @@ private:
void _delete(bool p_word = false, bool p_all_to_right = false);
void _move_caret_document_start(bool p_select);
void _move_caret_document_end(bool p_select);
+ bool _should_remove_secondary_carets();
// Used in add_caret_at_carets
void _get_above_below_caret_line_column(int p_old_line, int p_old_wrap_index, int p_old_column, bool p_below, int &p_new_line, int &p_new_column, int p_last_fit_x = -1) const;