Skip to content

Commit

Permalink
Yield keyboard focus on search field when selection is changed
Browse files Browse the repository at this point in the history
Deregister event handlers for selection change on dispose
  • Loading branch information
drogoganor committed Jan 22, 2024
1 parent 9d154d3 commit d2f83ac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
14 changes: 14 additions & 0 deletions OpenRA.Mods.Common/Widgets/Logic/Editor/CommonSelectorLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ protected CommonSelectorLogic(Widget widget, ModData modData, World world, World
return true;
};

Editor.DefaultBrush.SelectionChanged += HandleSelectionChanged;

var none = TranslationProvider.GetString(None);
var searchResults = TranslationProvider.GetString(SearchResults);
var all = TranslationProvider.GetString(All);
Expand Down Expand Up @@ -103,6 +105,18 @@ protected CommonSelectorLogic(Widget widget, ModData modData, World world, World
};
}

protected override void Dispose(bool disposing)
{
Editor.DefaultBrush.SelectionChanged -= HandleSelectionChanged;

base.Dispose(disposing);
}

void HandleSelectionChanged()
{
SearchTextField.YieldKeyboardFocus();
}

protected Widget CreateCategoriesPanel(ScrollPanelWidget panel)
{
var categoriesPanel = Ui.LoadWidget("CATEGORY_FILTER_PANEL", null, new WidgetArgs());
Expand Down
7 changes: 7 additions & 0 deletions OpenRA.Mods.Common/Widgets/Logic/Editor/MapEditorTabsLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ public MapEditorTabsLogic(Widget widget)
SetupTab("HISTORY_TAB", "HISTORY_WIDGETS", MenuType.History);
}

protected override void Dispose(bool disposing)
{
editor.DefaultBrush.SelectionChanged -= HandleSelectionChanged;

base.Dispose(disposing);
}

void SetupTab(string buttonId, string tabId, MenuType tabType)
{
if (buttonId != null)
Expand Down

0 comments on commit d2f83ac

Please sign in to comment.