Skip to content

Commit e675154

Browse files
committed
Merge pull request #68089 from alfredbaudisch/remove-secondary-carets
Shortcut and Bind to Remove Secondary Carets
2 parents 2043665 + fcff978 commit e675154

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

core/input/input_map.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ static const _BuiltinActionDisplayName _builtin_action_display_names[] = {
342342
{ "ui_text_select_all", TTRC("Select All") },
343343
{ "ui_text_select_word_under_caret", TTRC("Select Word Under Caret") },
344344
{ "ui_text_add_selection_for_next_occurrence", TTRC("Add Selection for Next Occurrence") },
345+
{ "ui_text_remove_secondary_carets", TTRC("Remove Secondary Carets") },
345346
{ "ui_text_toggle_insert_mode", TTRC("Toggle Insert Mode") },
346347
{ "ui_text_submit", TTRC("Text Submitted") },
347348
{ "ui_graph_duplicate", TTRC("Duplicate Nodes") },
@@ -671,6 +672,10 @@ const HashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() {
671672
inputs.push_back(InputEventKey::create_reference(Key::D | KeyModifierMask::CMD_OR_CTRL));
672673
default_builtin_cache.insert("ui_text_add_selection_for_next_occurrence", inputs);
673674

675+
inputs = List<Ref<InputEvent>>();
676+
inputs.push_back(InputEventKey::create_reference(Key::ESCAPE));
677+
default_builtin_cache.insert("ui_text_remove_secondary_carets", inputs);
678+
674679
inputs = List<Ref<InputEvent>>();
675680
inputs.push_back(InputEventKey::create_reference(Key::INSERT));
676681
default_builtin_cache.insert("ui_text_toggle_insert_mode", inputs);

doc/classes/ProjectSettings.xml

+4
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,10 @@
987987
Default [InputEventAction] to insert a new line after the current one.
988988
[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.
989989
</member>
990+
<member name="input/ui_text_remove_secondary_carets" type="Dictionary" setter="" getter="">
991+
If multiple carets are currently active, clear additional carets and keep just one caret.
992+
[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.
993+
</member>
990994
<member name="input/ui_text_scroll_down" type="Dictionary" setter="" getter="">
991995
Default [InputEventAction] to scroll down one line of text.
992996
[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.

scene/gui/text_edit.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -2067,6 +2067,11 @@ void TextEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
20672067
accept_event();
20682068
return;
20692069
}
2070+
if (k->is_action("ui_text_remove_secondary_carets", true) && _should_remove_secondary_carets()) {
2071+
remove_secondary_carets();
2072+
accept_event();
2073+
return;
2074+
}
20702075
if (k->is_action("ui_cut", true)) {
20712076
cut();
20722077
accept_event();
@@ -2819,6 +2824,10 @@ void TextEdit::_move_caret_document_end(bool p_select) {
28192824
}
28202825
}
28212826

2827+
bool TextEdit::_should_remove_secondary_carets() {
2828+
return carets.size() > 1;
2829+
}
2830+
28222831
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 {
28232832
if (p_last_fit_x == -1) {
28242833
p_last_fit_x = _get_column_x_offset_for_line(p_old_column, p_old_line, p_old_column);

scene/gui/text_edit.h

+1
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ class TextEdit : public Control {
597597
void _delete(bool p_word = false, bool p_all_to_right = false);
598598
void _move_caret_document_start(bool p_select);
599599
void _move_caret_document_end(bool p_select);
600+
bool _should_remove_secondary_carets();
600601

601602
// Used in add_caret_at_carets
602603
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;

0 commit comments

Comments
 (0)