Fix right click in selection of additional caret

This commit is contained in:
Jean-Michel Bernard 2023-04-30 18:28:21 +02:00
parent 43bf0b5e04
commit 5c06c030f2
2 changed files with 34 additions and 23 deletions

View File

@ -1805,20 +1805,26 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
int col = pos.x; int col = pos.x;
tx->set_move_caret_on_right_click_enabled(EDITOR_GET("text_editor/behavior/navigation/move_caret_on_right_click")); tx->set_move_caret_on_right_click_enabled(EDITOR_GET("text_editor/behavior/navigation/move_caret_on_right_click"));
int caret_clicked = -1;
if (tx->is_move_caret_on_right_click_enabled()) { if (tx->is_move_caret_on_right_click_enabled()) {
tx->remove_secondary_carets();
if (tx->has_selection()) { if (tx->has_selection()) {
int from_line = tx->get_selection_from_line(); for (int i = 0; i < tx->get_caret_count(); i++) {
int to_line = tx->get_selection_to_line(); int from_line = tx->get_selection_from_line(i);
int from_column = tx->get_selection_from_column(); int to_line = tx->get_selection_to_line(i);
int to_column = tx->get_selection_to_column(); int from_column = tx->get_selection_from_column(i);
int to_column = tx->get_selection_to_column(i);
if (row < from_line || row > to_line || (row == from_line && col < from_column) || (row == to_line && col > to_column)) { 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 // Right click in one of the selected text
caret_clicked = i;
break;
}
}
}
if (!caret_clicked) {
tx->deselect(); tx->deselect();
} tx->remove_secondary_carets();
} caret_clicked = 0;
if (!tx->has_selection()) {
tx->set_caret_line(row, false, false); tx->set_caret_line(row, false, false);
tx->set_caret_column(col); tx->set_caret_column(col);
} }
@ -1826,10 +1832,10 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
String word_at_pos = tx->get_word_at_pos(local_pos); String word_at_pos = tx->get_word_at_pos(local_pos);
if (word_at_pos.is_empty()) { if (word_at_pos.is_empty()) {
word_at_pos = tx->get_word_under_caret(0); word_at_pos = tx->get_word_under_caret(caret_clicked);
} }
if (word_at_pos.is_empty()) { if (word_at_pos.is_empty()) {
word_at_pos = tx->get_selected_text(0); word_at_pos = tx->get_selected_text(caret_clicked);
} }
bool has_color = (word_at_pos == "Color"); bool has_color = (word_at_pos == "Color");

View File

@ -1851,23 +1851,28 @@ void TextEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
Point2i pos = get_line_column_at_pos(mpos); Point2i pos = get_line_column_at_pos(mpos);
int row = pos.y; int row = pos.y;
int col = pos.x; int col = pos.x;
int caret = carets.size() - 1;
bool selection_clicked = false;
if (is_move_caret_on_right_click_enabled()) { if (is_move_caret_on_right_click_enabled()) {
if (has_selection(caret)) { if (has_selection()) {
int from_line = get_selection_from_line(caret); for (int i = 0; i < get_caret_count(); i++) {
int to_line = get_selection_to_line(caret); int from_line = get_selection_from_line(i);
int from_column = get_selection_from_column(caret); int to_line = get_selection_to_line(i);
int to_column = get_selection_to_column(caret); 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)) { 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. // Right click in one of the selected text
deselect(caret); selection_clicked = true;
break;
} }
} }
if (!has_selection(caret)) { }
set_caret_line(row, true, false, 0, caret); if (!selection_clicked) {
set_caret_column(col, true, caret); deselect();
remove_secondary_carets();
set_caret_line(row, false, false);
set_caret_column(col);
} }
merge_overlapping_carets(); merge_overlapping_carets();
} }