From 64e76e1a90bf5c21f56145addfda3d1b7c83f01d Mon Sep 17 00:00:00 2001 From: Ivaylo Draganov Date: Sun, 4 Jul 2021 16:24:34 +0300 Subject: [PATCH] Make text fields yield keyboard focus on "Esc" in a consistent way - search fields clear the input and yield if empty - chat field and actor edit field yield without clearing --- .../Widgets/Logic/AssetBrowserLogic.cs | 13 ++++++++++++- .../Widgets/Logic/Editor/ActorEditLogic.cs | 6 +----- .../Widgets/Logic/Editor/CommonSelectorLogic.cs | 10 ++++++++-- .../Widgets/Logic/Lobby/LobbyLogic.cs | 2 +- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs index 7628997294..a4c5151d4c 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs @@ -133,7 +133,18 @@ namespace OpenRA.Mods.Common.Widgets.Logic filenameInput = panel.Get("FILENAME_INPUT"); filenameInput.OnTextEdited = () => ApplyFilter(); - filenameInput.OnEscKey = _ => filenameInput.YieldKeyboardFocus(); + filenameInput.OnEscKey = _ => + { + if (string.IsNullOrEmpty(filenameInput.Text)) + filenameInput.YieldKeyboardFocus(); + else + { + filenameInput.Text = ""; + filenameInput.OnTextEdited(); + } + + return true; + }; var frameContainer = panel.GetOrNull("FRAME_SELECTOR"); if (frameContainer != null) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs index cd28f2fada..9d1b1553d7 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs @@ -114,11 +114,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic && editor.CurrentBrush == editor.DefaultBrush && Game.RunTime > lastScrollTime + scrollVisibleTimeout; - actorIDField.OnEscKey = _ => - { - actorIDField.YieldKeyboardFocus(); - return true; - }; + actorIDField.OnEscKey = _ => actorIDField.YieldKeyboardFocus(); actorIDField.OnTextEdited = () => { diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/CommonSelectorLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/CommonSelectorLogic.cs index e9ae902509..b703d877b3 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/CommonSelectorLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/CommonSelectorLogic.cs @@ -46,8 +46,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic SearchTextField = widget.Get("SEARCH_TEXTFIELD"); SearchTextField.OnEscKey = _ => { - SearchTextField.Text = ""; - SearchTextField.YieldKeyboardFocus(); + if (string.IsNullOrEmpty(SearchTextField.Text)) + SearchTextField.YieldKeyboardFocus(); + else + { + SearchTextField.Text = ""; + SearchTextField.OnTextEdited(); + } + return true; }; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs index cf9ffb9d24..f48da4ff52 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs @@ -436,7 +436,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic return true; }; - chatTextField.OnEscKey = _ => { chatTextField.Text = ""; return true; }; + chatTextField.OnEscKey = _ => chatTextField.YieldKeyboardFocus(); lobbyChatPanel = lobby.Get("CHAT_DISPLAY"); chatTemplate = lobbyChatPanel.Get("CHAT_TEMPLATE");