-
Notifications
You must be signed in to change notification settings - Fork 328
FIX: Re-focus Action after RedrawUI #2043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ae57762
e36826e
aeedaec
6094fc4
3136869
71cbe4e
c564749
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ internal class ActionsTreeView : ViewBase<ActionsTreeView.ViewState> | |
| private readonly ScrollView m_PropertiesScrollview; | ||
|
|
||
| private bool m_RenameOnActionAdded; | ||
| private bool m_FocusOnRenameActionFinish; | ||
| private readonly CollectionViewSelectionChangeFilter m_ActionsTreeViewSelectionChangeFilter; | ||
|
|
||
| //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) | |
|
|
||
| // Don't want to show action properties if there's no actions. | ||
| m_PropertiesScrollview.visible = m_ActionsTreeView.GetTreeCount() > 0; | ||
|
|
||
| FinishActionRename(viewState.newElementID); | ||
| } | ||
|
|
||
| private void OnDraggedItem(DragPerformEvent evt) | ||
|
|
@@ -308,6 +311,17 @@ internal void RenameActionItem(int index) | |
| m_ActionsTreeView.GetRootElementForIndex(index)?.Q<InputActionsTreeViewItem>()?.FocusOnRenameTextField(); | ||
| } | ||
|
|
||
| private void FinishActionRename(int id) | ||
| { | ||
| if (!m_FocusOnRenameActionFinish || id == -1) | ||
| return; | ||
| m_ActionsTreeView.ScrollToItemById(id); | ||
| var treeViewItem = m_ActionsTreeView.GetRootElementForId(id)?.Q<InputActionsTreeViewItem>(); | ||
| treeViewItem?.FocusOnRenameFinish(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it really needs to use this new function ? Locally it seems to work well with treeViewItem?.FocusOnRenameFinish(); replaced by treeViewItem?.Focus(); |
||
|
|
||
| m_FocusOnRenameActionFinish = false; | ||
| } | ||
|
|
||
| internal void AddAction() | ||
| { | ||
| Dispatch(Commands.AddAction()); | ||
|
|
@@ -369,6 +383,8 @@ private void ChangeActionOrCompositName(ActionOrBindingData data, string newName | |
| Dispatch(Commands.ChangeActionName(data.actionMapIndex, data.name, newName)); | ||
| else if (data.isComposite) | ||
| Dispatch(Commands.ChangeCompositeName(data.actionMapIndex, data.bindingIndex, newName)); | ||
|
|
||
| m_FocusOnRenameActionFinish = true; | ||
| } | ||
|
|
||
| internal int GetMapCount() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,9 @@ internal class InputActionsTreeViewItem : VisualElement | |
| private const string kRenameTextField = "rename-text-field"; | ||
| public event EventCallback<string> EditTextFinished; | ||
|
|
||
| // for testing purposes to know if the item is focused to accept input | ||
| internal bool IsTextFieldFocused { get; private set; } = false; | ||
|
|
||
| private bool m_IsEditing; | ||
| private static InputActionsTreeViewItem s_EditingItem = null; | ||
|
|
||
|
|
@@ -34,9 +37,13 @@ public InputActionsTreeViewItem() | |
| renameTextfield.selectAllOnFocus = true; | ||
| renameTextfield.selectAllOnMouseUp = false; | ||
|
|
||
|
|
||
| RegisterCallback<MouseDownEvent>(OnMouseDownEventForRename); | ||
| renameTextfield.RegisterCallback<FocusOutEvent>(e => OnEditTextFinished()); | ||
| renameTextfield.RegisterCallback<FocusInEvent>(e => IsTextFieldFocused = true); | ||
| renameTextfield.RegisterCallback<FocusOutEvent>(e => | ||
| { | ||
| OnEditTextFinished(); | ||
| IsTextFieldFocused = false; | ||
| }); | ||
| } | ||
|
|
||
| public Label label => this.Q<Label>(); | ||
|
|
@@ -99,6 +106,19 @@ public static void CancelRename() | |
| s_EditingItem?.OnEditTextFinished(); | ||
| } | ||
|
|
||
| public void FocusOnRenameFinish() | ||
| { | ||
| if (m_IsEditing) | ||
| return; | ||
|
|
||
| //FocusOnRenameTextField() changes the focus to the renameTextfield explicitly, the focus needs to | ||
| //get moved again using a similar workaround when finished editing text | ||
| //Everything else has already been taken restored in OnEditTextFinished() but this has to happen after | ||
| //listView/treeView reclaims the focus in RedrawUI | ||
| label.Q<Label>().Focus(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have some concern on this line. |
||
| IsTextFieldFocused = false; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IsTextFieldFocused should not be changed here. It should be driven by ui toolkit when the item lose focus. Is it necessary? |
||
| } | ||
|
|
||
| async void DelayCall() | ||
| { | ||
| await Task.Delay(120); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great to see a test for this! There were a lot of cases on renaming and focus issues already.