Skip to content

Conversation

@tspiller
Copy link
Collaborator

@tspiller tspiller commented Nov 1, 2024

Description

FocusOnRenameTextField() changes the focus to the renameTextfield explicitly, this moves the focus back again using a similar workaround when finished editing text.

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.

@tspiller tspiller requested review from bmalrat and ritamerkl November 1, 2024 15:37
@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
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

}

[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
@tspiller tspiller changed the title FIX: Store ActionsTreeView current focus for restoring after RedrawUI FIX: Re-focus Action after RedrawUI Nov 19, 2024
Copy link
Collaborator

@ritamerkl ritamerkl left a comment

Choose a reason for hiding this comment

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

I don't have any objections, it looks good to me. @bmalrat has more insights on the UITK focus particularities though. I also add @Pauliusd01 for review.

@ritamerkl ritamerkl requested a review from Pauliusd01 November 19, 2024 15:36
@tspiller tspiller marked this pull request as ready for review November 20, 2024 14:43
Copy link
Collaborator

@benoitalain benoitalain left a comment

Choose a reason for hiding this comment

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

If it works, it works. Since you're extending TreeViewItem, which already does a lot of things, I don't think it would be easy to rewrite the Rename logic to make the item not lose focus in the first place. If you want more insight on TreeViewItem itself though, you can ask Guillaume Riendeau.

//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();
IsTextFieldFocused = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The 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?

//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();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have some concern on this line.
If the rename end by a clic in an other area, like action maps list, does it steal the focus?

return;
m_ActionsTreeView.ScrollToItemById(id);
var treeViewItem = m_ActionsTreeView.GetRootElementForId(id)?.Q<InputActionsTreeViewItem>();
treeViewItem?.FocusOnRenameFinish();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it really needs to use this new function ?
the Id here might not be the expected one. If during the rename you click on another element "id" will be the selected id and not the one that was renamed.

Locally it seems to work well with treeViewItem?.FocusOnRenameFinish(); replaced by treeViewItem?.Focus();

@tspiller tspiller closed this Dec 9, 2024
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.

6 participants