Skip to content

Commit

Permalink
Deselect multi caret when alt clicking on it
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusElg committed Sep 3, 2023
1 parent 6758a7f commit aac1070
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions scene/gui/text_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1752,11 +1752,27 @@ void TextEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
const int triple_click_tolerance = 5;
bool is_triple_click = (!mb->is_double_click() && (OS::get_singleton()->get_ticks_msec() - last_dblclk) < triple_click_timeout && mb->get_position().distance_to(last_dblclk_pos) < triple_click_tolerance);

if (!is_mouse_over_selection() && !mb->is_double_click() && !is_triple_click) {
if (!mb->is_double_click() && !is_triple_click) {
if (mb->is_alt_pressed()) {
prev_line = row;
prev_col = col;

// Remove caret at clicked location.
if (carets.size() > 1) {
for (int i = 0; i < carets.size(); i++) {
// Deselect if clicked on caret or its selection.
if ((get_caret_column(i) == col && get_caret_line(i) == row) || is_mouse_over_selection(true, i)) {
remove_caret(i);
last_dblclk = 0;
return;
}
}
}

if (is_mouse_over_selection()) {
return;
}

caret = add_caret(row, col);
if (caret == -1) {
return;
Expand All @@ -1766,7 +1782,7 @@ void TextEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
carets.write[caret].selection.selecting_column = col;

last_dblclk = 0;
} else if (!mb->is_shift_pressed()) {
} else if (!mb->is_shift_pressed() && !is_mouse_over_selection()) {
caret = 0;
remove_secondary_carets();
}
Expand Down

0 comments on commit aac1070

Please sign in to comment.