From 6307b0be3cbce28cbdcc4cd8af1eb12507326d8a Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Mon, 7 Aug 2023 10:52:28 +0200 Subject: [PATCH] Dismiss currently visible or upcoming tooltips when pressing Escape This is standard UI behavior in most applications out there. --- scene/main/viewport.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 54444b6828d..0cd395359f8 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -2184,6 +2184,18 @@ void Viewport::_gui_input_event(Ref p_event) { return; } + if (p_event->is_action_pressed("ui_cancel")) { + // Cancel tooltip timer or hide tooltip when pressing Escape (this is standard behavior in most applications). + _gui_cancel_tooltip(); + if (gui.tooltip_popup) { + // If a tooltip was hidden, prevent other actions associated with `ui_cancel` from occurring. + // For instance, this prevents the node from being deselected when pressing Escape + // to hide a documentation tooltip in the inspector. + set_input_as_handled(); + return; + } + } + if (gui.key_focus && !gui.key_focus->is_visible_in_tree()) { gui.key_focus->release_focus(); }