From a9bf3de08ed8ad55858f8a723b6395a68e6bc399 Mon Sep 17 00:00:00 2001 From: Markus Sauermann <6299227+Sauermann@users.noreply.github.com> Date: Mon, 29 May 2023 00:29:44 +0200 Subject: [PATCH] Fix InputEvent being used twice A single mouse click can cause multiple actions, which contradicts the paradigm that a single Input Event should cause only a single action. The solution consists of two parts: 1. Physics Picking as the last step during viewport input event handling, currently doesn't set the event as handled. This PR sets the event as handled in the case of physics picking. 2. After an InputEvent is processed by a SubVieportContainer, it is sent to its parent, even if it set as handled within the SubViewport. This PR adds an additional test to check if the event is handled before propagating the event to the parent Control. --- scene/main/viewport.cpp | 6 ++++++ tests/scene/test_text_edit.h | 1 + 2 files changed, 7 insertions(+) diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 1cc4fbc635d..8548eb3a06b 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -1564,6 +1564,11 @@ bool Viewport::_gui_call_input(Control *p_control, const Ref &p_inpu } } + if (is_input_handled()) { + // Break after Physics Picking in SubViewport. + break; + } + if (ci->is_set_as_top_level()) { break; } @@ -3045,6 +3050,7 @@ void Viewport::push_unhandled_input(const Ref &p_event, bool p_local )) { physics_picking_events.push_back(ev); + set_input_as_handled(); } } } diff --git a/tests/scene/test_text_edit.h b/tests/scene/test_text_edit.h index f3f2b4cb342..67d473128ee 100644 --- a/tests/scene/test_text_edit.h +++ b/tests/scene/test_text_edit.h @@ -38,6 +38,7 @@ namespace TestTextEdit { TEST_CASE("[SceneTree][TextEdit] text entry") { + SceneTree::get_singleton()->get_root()->set_physics_object_picking(false); TextEdit *text_edit = memnew(TextEdit); SceneTree::get_singleton()->get_root()->add_child(text_edit); text_edit->grab_focus();