Skip to content

Commit 61808e9

Browse files
committed
Merge pull request #91778 from kitbdev/selection-cancel
Fix TextEdit mouse selection and scroll cancel
2 parents 0f40078 + 73d813a commit 61808e9

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

scene/gui/text_edit.cpp

+21-3
Original file line numberDiff line numberDiff line change
@@ -1637,6 +1637,7 @@ void TextEdit::_notification(int p_what) {
16371637
}
16381638

16391639
if (has_ime_text() && has_selection()) {
1640+
set_selection_mode(SELECTION_MODE_NONE);
16401641
delete_selection();
16411642
}
16421643

@@ -1965,6 +1966,7 @@ void TextEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
19651966
_reset_caret_blink_timer();
19661967
apply_ime();
19671968
_cancel_drag_and_drop_text();
1969+
set_selection_mode(SELECTION_MODE_NONE);
19681970

19691971
Point2i pos = get_line_column_at_pos(mpos);
19701972
int mouse_line = pos.y;
@@ -4743,6 +4745,8 @@ void TextEdit::add_caret_at_carets(bool p_below) {
47434745
}
47444746
const int last_line_max_wrap = get_line_wrap_count(text.size() - 1);
47454747

4748+
set_selection_mode(SELECTION_MODE_NONE);
4749+
47464750
begin_multicaret_edit();
47474751
int view_target_caret = -1;
47484752
int view_line = p_below ? -1 : INT_MAX;
@@ -5289,6 +5293,8 @@ void TextEdit::select_word_under_caret(int p_caret) {
52895293
return;
52905294
}
52915295

5296+
set_selection_mode(SELECTION_MODE_NONE);
5297+
52925298
for (int c = 0; c < carets.size(); c++) {
52935299
if (p_caret != -1 && p_caret != c) {
52945300
continue;
@@ -5342,6 +5348,8 @@ void TextEdit::add_selection_for_next_occurrence() {
53425348
return;
53435349
}
53445350

5351+
set_selection_mode(SELECTION_MODE_NONE);
5352+
53455353
const String &highlighted_text = get_selected_text(caret);
53465354
int column = get_selection_from_column(caret) + 1;
53475355
int line = get_selection_from_line(caret);
@@ -5373,6 +5381,8 @@ void TextEdit::skip_selection_for_next_occurrence() {
53735381
return;
53745382
}
53755383

5384+
set_selection_mode(SELECTION_MODE_NONE);
5385+
53765386
// Always use the last caret, to correctly search for
53775387
// the next occurrence that comes after this caret.
53785388
int caret = get_caret_count() - 1;
@@ -5916,6 +5926,9 @@ void TextEdit::set_line_as_first_visible(int p_line, int p_wrap_index) {
59165926
ERR_FAIL_COND(p_wrap_index < 0);
59175927
ERR_FAIL_COND(p_wrap_index > get_line_wrap_count(p_line));
59185928
set_v_scroll(get_scroll_pos_for_line(p_line, p_wrap_index));
5929+
5930+
scrolling = false;
5931+
minimap_clicked = false;
59195932
}
59205933

59215934
int TextEdit::get_first_visible_line() const {
@@ -5927,6 +5940,9 @@ void TextEdit::set_line_as_center_visible(int p_line, int p_wrap_index) {
59275940
ERR_FAIL_COND(p_wrap_index < 0);
59285941
ERR_FAIL_COND(p_wrap_index > get_line_wrap_count(p_line));
59295942

5943+
scrolling = false;
5944+
minimap_clicked = false;
5945+
59305946
int visible_rows = get_visible_line_count();
59315947
Point2i next_line = get_next_visible_line_index_offset_from(p_line, p_wrap_index, (-visible_rows / 2) - 1);
59325948
int first_line = p_line - next_line.x + 1;
@@ -5943,6 +5959,9 @@ void TextEdit::set_line_as_last_visible(int p_line, int p_wrap_index) {
59435959
ERR_FAIL_COND(p_wrap_index < 0);
59445960
ERR_FAIL_COND(p_wrap_index > get_line_wrap_count(p_line));
59455961

5962+
scrolling = false;
5963+
minimap_clicked = false;
5964+
59465965
Point2i next_line = get_next_visible_line_index_offset_from(p_line, p_wrap_index, -get_visible_line_count() - 1);
59475966
int first_line = p_line - next_line.x + 1;
59485967

@@ -6005,8 +6024,6 @@ void TextEdit::adjust_viewport_to_caret(int p_caret) {
60056024
ERR_FAIL_INDEX(p_caret, carets.size());
60066025

60076026
// Move viewport so the caret is visible on the screen vertically.
6008-
scrolling = false;
6009-
minimap_clicked = false;
60106027

60116028
int cur_line = get_caret_line(p_caret);
60126029
int cur_wrap = get_caret_wrap_index(p_caret);
@@ -7699,7 +7716,7 @@ void TextEdit::_selection_changed(int p_caret) {
76997716

77007717
void TextEdit::_click_selection_held() {
77017718
// Update the selection mode on a timer so it is updated when the view scrolls even if the mouse isn't moving.
7702-
if (!Input::get_singleton()->is_mouse_button_pressed(MouseButton::LEFT) || get_selection_mode() == SelectionMode::SELECTION_MODE_NONE) {
7719+
if (!Input::get_singleton()->is_mouse_button_pressed(MouseButton::LEFT)) {
77037720
click_select_held->stop();
77047721
return;
77057722
}
@@ -7714,6 +7731,7 @@ void TextEdit::_click_selection_held() {
77147731
_update_selection_mode_line();
77157732
} break;
77167733
default: {
7734+
click_select_held->stop();
77177735
break;
77187736
}
77197737
}

0 commit comments

Comments
 (0)