From e21c30ec11ed6ac90cc0a2a915879a850922a43e Mon Sep 17 00:00:00 2001 From: kobewi Date: Tue, 22 Aug 2023 16:29:00 +0200 Subject: [PATCH] Unfocus LineEdit when pressing Escape --- scene/gui/line_edit.cpp | 5 +++++ scene/gui/spin_box.cpp | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index bb727ff62cd7..4c1e591bd783 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -482,6 +482,11 @@ void LineEdit::gui_input(const Ref &p_event) { return; } + if (k->is_action("ui_cancel")) { + release_focus(); + return; + } + if (is_shortcut_keys_enabled()) { if (k->is_action("ui_copy", true)) { copy_text(); diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index 7cb54f24ea93..4af694ae3dfb 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -210,6 +210,11 @@ void SpinBox::_line_edit_focus_exit() { if (line_edit->is_menu_visible()) { return; } + // Discontinue because the focus_exit was caused by canceling. + if (Input::get_singleton()->is_action_pressed("ui_cancel")) { + _update_text(); + return; + } _text_submitted(line_edit->get_text()); }