From ff98395556a9a5fd497547efb47024e19e368bb5 Mon Sep 17 00:00:00 2001 From: Yuri Sizov Date: Thu, 9 Mar 2023 14:56:52 +0100 Subject: [PATCH] Prevent passing events from CodeEdit to TextEdit when code completion is active --- scene/gui/code_edit.cpp | 29 +++++++++++++++++++++++++++-- scene/gui/code_edit.h | 1 + 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index 91c4fa37612..39ae6585bc0 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -261,7 +261,6 @@ void CodeEdit::_notification(int p_what) { void CodeEdit::gui_input(const Ref &p_gui_input) { Ref mb = p_gui_input; - if (mb.is_valid()) { /* Ignore mouse clicks in IME input mode. */ if (has_ime_text()) { @@ -270,14 +269,24 @@ void CodeEdit::gui_input(const Ref &p_gui_input) { if (is_code_completion_scroll_pressed && mb->get_button_index() == MouseButton::LEFT) { 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(); return; } if (code_completion_active && code_completion_rect.has_point(mb->get_position())) { if (!mb->is_pressed()) { + accept_event(); return; } + is_code_completion_drag_started = true; switch (mb->get_button_index()) { case MouseButton::WHEEL_UP: { @@ -309,19 +318,23 @@ void CodeEdit::gui_input(const Ref &p_gui_input) { break; } + accept_event(); return; } else if (code_completion_active && code_completion_scroll_rect.has_point(mb->get_position())) { if (mb->get_button_index() != MouseButton::LEFT) { + accept_event(); return; } if (mb->is_pressed()) { + is_code_completion_drag_started = true; is_code_completion_scroll_pressed = true; _update_scroll_selected_line(mb->get_position().y); queue_redraw(); } + accept_event(); return; } @@ -394,14 +407,21 @@ void CodeEdit::gui_input(const Ref &p_gui_input) { bool scroll_hovered = code_completion_scroll_rect.has_point(mpos); if (is_code_completion_scroll_hovered != scroll_hovered) { is_code_completion_scroll_hovered = scroll_hovered; + accept_event(); queue_redraw(); } if (is_code_completion_scroll_pressed) { _update_scroll_selected_line(mpos.y); + accept_event(); queue_redraw(); return; } + + if (code_completion_active && code_completion_rect.has_point(mm->get_position())) { + accept_event(); + return; + } } Ref k = p_gui_input; @@ -412,7 +432,11 @@ void CodeEdit::gui_input(const Ref &p_gui_input) { bool update_code_completion = false; 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; } @@ -2084,6 +2108,7 @@ void CodeEdit::cancel_code_completion() { } code_completion_forced = false; code_completion_active = false; + is_code_completion_drag_started = false; queue_redraw(); } diff --git a/scene/gui/code_edit.h b/scene/gui/code_edit.h index 55fc5aa2aeb..e793c9c6ae4 100644 --- a/scene/gui/code_edit.h +++ b/scene/gui/code_edit.h @@ -211,6 +211,7 @@ private: bool code_completion_active = false; bool is_code_completion_scroll_hovered = false; bool is_code_completion_scroll_pressed = false; + bool is_code_completion_drag_started = false; Vector code_completion_options; int code_completion_line_ofs = 0; int code_completion_current_selected = 0;