Skip to content
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

FIX: Store ActionsTreeView current focus for restoring after RedrawUI #2043

Draft
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

tspiller
Copy link
Collaborator

@tspiller tspiller commented Nov 1, 2024

Description

When calling ActionsTreeView.RedrawUI after renaming an Action the call to Rebuild clears any focus that the renamed element had. This saves the currently focused element and restores it back to the same focus if there was one.

Testing status & QA

Tested locally on 6000. Added new CanRenameAction test.

Overall Product Risks

  • Complexity: Low
  • Halo Effect: None

Comments to reviewers

Please describe any additional information such as what to focus on, or historical info for the reviewers.

Checklist

Before review:

  • Changelog entry added.
    • Explains the change in Changed, Fixed, Added sections.
    • For API change contains an example snippet and/or migration example.
    • JIRA ticket linked, example (case %%). If it is a private issue, just add the case ID without a link.
    • Jira port for the next release set as "Resolved".
  • Tests added/changed, if applicable.
    • Functional tests Area_CanDoX, Area_CanDoX_EvenIfYIsTheCase, Area_WhenIDoX_AndYHappens_ThisIsTheResult.
    • Performance tests.
    • Integration tests.
  • Docs for new/changed API's.
    • Xmldoc cross references are set correctly.
    • Added explanation how the API works.
    • Usage code examples added.
    • The manual is updated, if needed.

During merge:

  • Commit message for squash-merge is prefixed with one of the list:
    • NEW: ___.
    • FIX: ___.
    • DOCS: ___.
    • CHANGE: ___.
    • RELEASE: 1.1.0-preview.3.

After merge:

  • Create forward/backward port if needed. If you are blocked from creating a forward port now please add a task to ISX-1444.

@unity-cla-assistant
Copy link

unity-cla-assistant commented Nov 1, 2024

CLA assistant check
All committers have signed the CLA.

@tspiller tspiller marked this pull request as draft November 1, 2024 15:56
@@ -202,6 +202,9 @@ public override void DestroyView()

public override void RedrawUI(ViewState viewState)
{
// Store the current focus before Clear/Rebuild
Focusable focusedElement = m_ActionsTreeView.focusController.focusedElement;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not a good workaround because the focused element that is retrieved here might not be valid after the m_ActionsTreeView.Rebuild().
The Rebuild can create and/or recycle visualelement. https://docs.unity3d.com/6000.0/Documentation/ScriptReference/UIElements.BaseVerticalCollectionView.Rebuild.html
The focused element might also not represent the right sub visualelement since it's a stack of focused element.

RefreshItems() could mitigate the refres problem but the behavior is not predictable across version
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/UIElements.BaseVerticalCollectionView.RefreshItems.html

Copy link
Collaborator Author

@tspiller tspiller Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see now that it is not reliable since the test I added fails at random.
RefreshItems() doesn't work because the issue occurs in virtualizationController.Refresh() which is called by both. RefreshItems causes the issue intermittently instead, but also causes some other selection issues

@@ -17,6 +17,7 @@ however, it has to be formatted properly to pass verification tests.
- Fixed pointerId staying the same when simultaneously releasing and then pressing in the same frame on mobile using touch. [ISXB-1006](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-845)
- Fixed ISubmitHandler.OnSubmit event processing when operating in Manual Update mode (ISXB-1141)
- Fixed Rename mode is not entered and name is autocompleted to default when creating a new Action Map on 2022.3. [ISXB-1151](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1151)
- Fixed arrow key navigation of Input Actions after Action rename [ISXB-1024](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1024)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a missing point at the end of the sentence.

@@ -173,5 +189,55 @@ public IEnumerator CanDeleteActionMap()
Assert.That(m_Window.currentAssetInEditor.actionMaps[0].name, Is.EqualTo("First Name"));
Assert.That(m_Window.currentAssetInEditor.actionMaps[1].name, Is.EqualTo("Third Name"));
}

[UnityTest]
public IEnumerator CanRenameAction()
Copy link
Collaborator

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.

@tspiller tspiller force-pushed the isxb-1024-action-navigation-after-rename branch from de1aa47 to aeedaec Compare November 13, 2024 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants