Merge pull request #74665 from YuriSizov/code-edit-is-a-complete-drag

Prevent passing events from CodeEdit to TextEdit when code completion is active
This commit is contained in:
Yuri Sizov 2023-03-20 16:47:45 +01:00 committed by GitHub
commit c311490600
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 2 deletions

View File

@ -261,7 +261,6 @@ void CodeEdit::_notification(int p_what) {
void CodeEdit::gui_input(const Ref<InputEvent> &p_gui_input) { void CodeEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
Ref<InputEventMouseButton> mb = p_gui_input; Ref<InputEventMouseButton> mb = p_gui_input;
if (mb.is_valid()) { if (mb.is_valid()) {
/* Ignore mouse clicks in IME input mode. */ /* Ignore mouse clicks in IME input mode. */
if (has_ime_text()) { if (has_ime_text()) {
@ -270,14 +269,24 @@ void CodeEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
if (is_code_completion_scroll_pressed && mb->get_button_index() == MouseButton::LEFT) { if (is_code_completion_scroll_pressed && mb->get_button_index() == MouseButton::LEFT) {
is_code_completion_scroll_pressed = false; is_code_completion_scroll_pressed = false;
accept_event();
queue_redraw();
return;
}
if (is_code_completion_drag_started && !mb->is_pressed()) {
is_code_completion_drag_started = false;
accept_event();
queue_redraw(); queue_redraw();
return; return;
} }
if (code_completion_active && code_completion_rect.has_point(mb->get_position())) { if (code_completion_active && code_completion_rect.has_point(mb->get_position())) {
if (!mb->is_pressed()) { if (!mb->is_pressed()) {
accept_event();
return; return;
} }
is_code_completion_drag_started = true;
switch (mb->get_button_index()) { switch (mb->get_button_index()) {
case MouseButton::WHEEL_UP: { case MouseButton::WHEEL_UP: {
@ -309,19 +318,23 @@ void CodeEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
break; break;
} }
accept_event();
return; return;
} else if (code_completion_active && code_completion_scroll_rect.has_point(mb->get_position())) { } else if (code_completion_active && code_completion_scroll_rect.has_point(mb->get_position())) {
if (mb->get_button_index() != MouseButton::LEFT) { if (mb->get_button_index() != MouseButton::LEFT) {
accept_event();
return; return;
} }
if (mb->is_pressed()) { if (mb->is_pressed()) {
is_code_completion_drag_started = true;
is_code_completion_scroll_pressed = true; is_code_completion_scroll_pressed = true;
_update_scroll_selected_line(mb->get_position().y); _update_scroll_selected_line(mb->get_position().y);
queue_redraw(); queue_redraw();
} }
accept_event();
return; return;
} }
@ -394,14 +407,21 @@ void CodeEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
bool scroll_hovered = code_completion_scroll_rect.has_point(mpos); bool scroll_hovered = code_completion_scroll_rect.has_point(mpos);
if (is_code_completion_scroll_hovered != scroll_hovered) { if (is_code_completion_scroll_hovered != scroll_hovered) {
is_code_completion_scroll_hovered = scroll_hovered; is_code_completion_scroll_hovered = scroll_hovered;
accept_event();
queue_redraw(); queue_redraw();
} }
if (is_code_completion_scroll_pressed) { if (is_code_completion_scroll_pressed) {
_update_scroll_selected_line(mpos.y); _update_scroll_selected_line(mpos.y);
accept_event();
queue_redraw(); queue_redraw();
return; return;
} }
if (code_completion_active && code_completion_rect.has_point(mm->get_position())) {
accept_event();
return;
}
} }
Ref<InputEventKey> k = p_gui_input; Ref<InputEventKey> k = p_gui_input;
@ -412,7 +432,11 @@ void CodeEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
bool update_code_completion = false; bool update_code_completion = false;
if (!k.is_valid()) { if (!k.is_valid()) {
TextEdit::gui_input(p_gui_input); // MouseMotion events should not be handled by TextEdit logic if we're
// currently clicking and dragging from the code completion panel.
if (!mm.is_valid() || !is_code_completion_drag_started) {
TextEdit::gui_input(p_gui_input);
}
return; return;
} }
@ -2084,6 +2108,7 @@ void CodeEdit::cancel_code_completion() {
} }
code_completion_forced = false; code_completion_forced = false;
code_completion_active = false; code_completion_active = false;
is_code_completion_drag_started = false;
queue_redraw(); queue_redraw();
} }

View File

@ -211,6 +211,7 @@ private:
bool code_completion_active = false; bool code_completion_active = false;
bool is_code_completion_scroll_hovered = false; bool is_code_completion_scroll_hovered = false;
bool is_code_completion_scroll_pressed = false; bool is_code_completion_scroll_pressed = false;
bool is_code_completion_drag_started = false;
Vector<ScriptLanguage::CodeCompletionOption> code_completion_options; Vector<ScriptLanguage::CodeCompletionOption> code_completion_options;
int code_completion_line_ofs = 0; int code_completion_line_ofs = 0;
int code_completion_current_selected = 0; int code_completion_current_selected = 0;