Skip to content

Commit e36826e

Browse files
committed
Refocus after Action rename
1 parent ae57762 commit e36826e

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionsTreeView.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ internal class ActionsTreeView : ViewBase<ActionsTreeView.ViewState>
2424
private readonly ScrollView m_PropertiesScrollview;
2525

2626
private bool m_RenameOnActionAdded;
27+
private bool m_FocusOnRenameActionFinish;
2728
private readonly CollectionViewSelectionChangeFilter m_ActionsTreeViewSelectionChangeFilter;
2829

2930
//save TreeView element id's of individual input actions and bindings to ensure saving of expanded state
@@ -215,6 +216,8 @@ public override void RedrawUI(ViewState viewState)
215216

216217
// Don't want to show action properties if there's no actions.
217218
m_PropertiesScrollview.visible = m_ActionsTreeView.GetTreeCount() > 0;
219+
220+
FinishActionRename(viewState.newElementID);
218221
}
219222

220223
private void OnDraggedItem(DragPerformEvent evt)
@@ -307,6 +310,17 @@ internal void RenameActionItem(int index)
307310
m_ActionsTreeView.ScrollToItem(index);
308311
m_ActionsTreeView.GetRootElementForIndex(index)?.Q<InputActionsTreeViewItem>()?.FocusOnRenameTextField();
309312
}
313+
314+
private void FinishActionRename(int id)
315+
{
316+
if (!m_FocusOnRenameActionFinish || id == -1)
317+
return;
318+
m_ActionsTreeView.ScrollToItemById(id);
319+
var treeViewItem = m_ActionsTreeView.GetRootElementForId(id)?.Q<InputActionsTreeViewItem>();
320+
treeViewItem?.FocusOnRenameFinish();
321+
322+
m_FocusOnRenameActionFinish = false;
323+
}
310324

311325
internal void AddAction()
312326
{
@@ -369,6 +383,8 @@ private void ChangeActionOrCompositName(ActionOrBindingData data, string newName
369383
Dispatch(Commands.ChangeActionName(data.actionMapIndex, data.name, newName));
370384
else if (data.isComposite)
371385
Dispatch(Commands.ChangeCompositeName(data.actionMapIndex, data.bindingIndex, newName));
386+
387+
m_FocusOnRenameActionFinish = true;
372388
}
373389

374390
internal int GetMapCount()

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsTreeViewItem.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,18 @@ public static void CancelRename()
105105
{
106106
s_EditingItem?.OnEditTextFinished();
107107
}
108+
109+
public void FocusOnRenameFinish()
110+
{
111+
if (m_IsEditing)
112+
return;
113+
114+
//FocusOnRenameTextField() changes the focus to the renameTextfield explicitly, the focus needs to
115+
//get moved again using a similar workaround when finished editing text
116+
//Everything else has already been taken restored in OnEditTextFinished() but this has to happen after
117+
//listView/treeView reclaims the focus in RedrawUI
118+
label.Q<Label>().Focus();
119+
}
108120

109121
async void DelayCall()
110122
{

0 commit comments

Comments
 (0)