summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/input/input_map.cpp5
-rw-r--r--doc/classes/ProjectSettings.xml4
-rw-r--r--scene/gui/text_edit.cpp9
-rw-r--r--scene/gui/text_edit.h1
4 files changed, 19 insertions, 0 deletions
diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp
index 233065fe8b..aebb9caa2f 100644
--- a/core/input/input_map.cpp
+++ b/core/input/input_map.cpp
@@ -342,6 +342,7 @@ static const _BuiltinActionDisplayName _builtin_action_display_names[] = {
{ "ui_text_select_all", TTRC("Select All") },
{ "ui_text_select_word_under_caret", TTRC("Select Word Under Caret") },
{ "ui_text_add_selection_for_next_occurrence", TTRC("Add Selection for Next Occurrence") },
+ { "ui_text_remove_secondary_carets", TTRC("Remove Secondary Carets") },
{ "ui_text_toggle_insert_mode", TTRC("Toggle Insert Mode") },
{ "ui_text_submit", TTRC("Text Submitted") },
{ "ui_graph_duplicate", TTRC("Duplicate Nodes") },
@@ -672,6 +673,10 @@ const HashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() {
default_builtin_cache.insert("ui_text_add_selection_for_next_occurrence", inputs);
inputs = List<Ref<InputEvent>>();
+ inputs.push_back(InputEventKey::create_reference(Key::ESCAPE));
+ default_builtin_cache.insert("ui_text_remove_secondary_carets", inputs);
+
+ inputs = List<Ref<InputEvent>>();
inputs.push_back(InputEventKey::create_reference(Key::INSERT));
default_builtin_cache.insert("ui_text_toggle_insert_mode", inputs);
diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml
index 7ac88377fb..91d9bdd4a2 100644
--- a/doc/classes/ProjectSettings.xml
+++ b/doc/classes/ProjectSettings.xml
@@ -987,6 +987,10 @@
Default [InputEventAction] to insert a new line after the current one.
[b]Note:[/b] Default [code]ui_*[/code] actions cannot be removed as they are necessary for the internal logic of several [Control]s. The events assigned to the action can however be modified.
</member>
+ <member name="input/ui_text_remove_secondary_carets" type="Dictionary" setter="" getter="">
+ If multiple carets are currently active, clear additional carets and keep just one caret.
+ [b]Note:[/b] Default [code]ui_*[/code] actions cannot be removed as they are necessary for the internal logic of several [Control]s. The events assigned to the action can however be modified.
+ </member>
<member name="input/ui_text_scroll_down" type="Dictionary" setter="" getter="">
Default [InputEventAction] to scroll down one line of text.
[b]Note:[/b] Default [code]ui_*[/code] actions cannot be removed as they are necessary for the internal logic of several [Control]s. The events assigned to the action can however be modified.
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;