summaryrefslogtreecommitdiff
path: root/scene/gui/text_edit.cpp
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2023-05-12 15:08:03 +0200
committerGitHub <noreply@github.com>2023-05-12 15:08:03 +0200
commit2ac4e3bb30517998916bb6b81b7b76788276038c (patch)
tree245bf4614ff38f3b0fcac813c1dde8c39b57732d /scene/gui/text_edit.cpp
parentfdf66b3472e5ca254a4f90c32f26c4702d46828b (diff)
parentfa8b32cbd4503e73a840bd1a1dd32d2a88cc3f45 (diff)
Merge pull request #76998 from akien-mga/4.0-cherrypicks
Cherry-picks for the 4.0 branch (future 4.0.3) - 4th batch
Diffstat (limited to 'scene/gui/text_edit.cpp')
-rw-r--r--scene/gui/text_edit.cpp31
1 files changed, 18 insertions, 13 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 814af12d60..310177dda7 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -1847,23 +1847,28 @@ void TextEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
Point2i pos = get_line_column_at_pos(mpos);
int row = pos.y;
int col = pos.x;
- int caret = carets.size() - 1;
+ bool selection_clicked = false;
if (is_move_caret_on_right_click_enabled()) {
- if (has_selection(caret)) {
- int from_line = get_selection_from_line(caret);
- int to_line = get_selection_to_line(caret);
- int from_column = get_selection_from_column(caret);
- int to_column = get_selection_to_column(caret);
-
- if (row < from_line || row > to_line || (row == from_line && col < from_column) || (row == to_line && col > to_column)) {
- // Right click is outside the selected text.
- deselect(caret);
+ if (has_selection()) {
+ for (int i = 0; i < get_caret_count(); i++) {
+ int from_line = get_selection_from_line(i);
+ int to_line = get_selection_to_line(i);
+ int from_column = get_selection_from_column(i);
+ int to_column = get_selection_to_column(i);
+
+ if (row >= from_line && row <= to_line && (row != from_line || col >= from_column) && (row != to_line || col <= to_column)) {
+ // Right click in one of the selected text
+ selection_clicked = true;
+ break;
+ }
}
}
- if (!has_selection(caret)) {
- set_caret_line(row, true, false, 0, caret);
- set_caret_column(col, true, caret);
+ if (!selection_clicked) {
+ deselect();
+ remove_secondary_carets();
+ set_caret_line(row, false, false);
+ set_caret_column(col);
}
merge_overlapping_carets();
}