Skip to content

Commit

Permalink
Make text fields yield keyboard focus on "Esc" in a consistent way
Browse files Browse the repository at this point in the history
- search fields clear the input and yield if empty
- chat field and actor edit field yield without clearing
  • Loading branch information
dragunoff committed Jul 4, 2021
1 parent 2ea6bfb commit 9617180
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
10 changes: 9 additions & 1 deletion OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs
Expand Up @@ -133,7 +133,15 @@ public AssetBrowserLogic(Widget widget, Action onExit, ModData modData, WorldRen

filenameInput = panel.Get<TextFieldWidget>("FILENAME_INPUT");
filenameInput.OnTextEdited = () => ApplyFilter();
filenameInput.OnEscKey = _ => filenameInput.YieldKeyboardFocus();
filenameInput.OnEscKey = _ =>
{
if (string.IsNullOrEmpty(filenameInput.Text))
filenameInput.YieldKeyboardFocus();
else
filenameInput.Text = "";
return true;
};

var frameContainer = panel.GetOrNull("FRAME_SELECTOR");
if (frameContainer != null)
Expand Down
6 changes: 1 addition & 5 deletions OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs
Expand Up @@ -114,11 +114,7 @@ public ActorEditLogic(Widget widget, World world, WorldRenderer worldRenderer, D
&& editor.CurrentBrush == editor.DefaultBrush
&& Game.RunTime > lastScrollTime + scrollVisibleTimeout;

actorIDField.OnEscKey = _ =>
{
actorIDField.YieldKeyboardFocus();
return true;
};
actorIDField.OnEscKey = _ => actorIDField.YieldKeyboardFocus();

actorIDField.OnTextEdited = () =>
{
Expand Down
Expand Up @@ -46,8 +46,11 @@ public CommonSelectorLogic(Widget widget, World world, WorldRenderer worldRender
SearchTextField = widget.Get<TextFieldWidget>("SEARCH_TEXTFIELD");
SearchTextField.OnEscKey = _ =>
{
SearchTextField.Text = "";
SearchTextField.YieldKeyboardFocus();
if (string.IsNullOrEmpty(SearchTextField.Text))
SearchTextField.YieldKeyboardFocus();
else
SearchTextField.Text = "";
return true;
};

Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs
Expand Up @@ -436,7 +436,7 @@ void ConnectionStateChanged(OrderManager om, string password, NetworkConnection
return true;
};

chatTextField.OnEscKey = _ => { chatTextField.Text = ""; return true; };
chatTextField.OnEscKey = _ => chatTextField.YieldKeyboardFocus();

lobbyChatPanel = lobby.Get<ScrollPanelWidget>("CHAT_DISPLAY");
chatTemplate = lobbyChatPanel.Get("CHAT_TEMPLATE");
Expand Down

0 comments on commit 9617180

Please sign in to comment.