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

Allow widgets to be rearranged by keyboard #3426

Merged
merged 3 commits into from
Jul 16, 2024
Merged

Conversation

krschau
Copy link
Collaborator

@krschau krschau commented Jul 12, 2024

Summary of the pull request

Allows widgets to be rearranged via Alt+Shift+LeftArrow and Alt+Shift+RightArrow keyboard commands.

Separately, create widget's ActionParser and ElementParser only once and reuse them, since they never change.

References and relevant issues

https://task.ms/49658818

Detailed description of the pull request / Additional comments

Validation steps performed

Validated locally.

PR checklist

  • Closes #xxx
  • Tests added/passed
  • Documentation updated
  • Telemetry compliance tasks completed for added/updated events

var index = ViewModel.PinnedWidgets.IndexOf(widgetViewModel);
_log.Information($"Move widget {widgetViewModel.WidgetDisplayTitle} at index {index} {key}");

if (key == VirtualKey.Left && index > 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this can be reduced to figuring out the new index in the if/else block.

else if (key == VirtualKey.Right && index < (ViewModel.PinnedWidgets.Count - 1))
{
// Setting focus before and after the move looks more natural than letting the focus move to the wrong element.
await FocusManager.TryFocusAsync(WidgetGridView.ItemsPanelRoot.Children.ElementAt(index + 1), FocusState.Keyboard);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the extra focus here, but not in the if case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There was nothing I could set focus on in the if case that would make the animation look less awkward. Someday I'd like better animations for both keyboard and the drag and drop scenario, but I'd rather unblock accessibility asap than hold anything up for that.

@@ -99,7 +101,8 @@
<ItemsPanelTemplate>
<controls:WidgetBoard XYFocusKeyboardNavigation="Enabled"
XYFocusRightNavigationStrategy="RectilinearDistance"
XYFocusLeftNavigationStrategy="RectilinearDistance"/>
XYFocusLeftNavigationStrategy="RectilinearDistance"
KeyUp="HandleKeyUpAsync" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Would promoting this to a command prevent any unexpected concurrent asynchronous execution behavior?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because it's in a ItemsPanelTempate, I can't bind to the command 🙁
microsoft/microsoft-ui-xaml#2508

{
_log.Debug($"Key up");

await _moveWidgetsLock.WaitAsync();
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see, is this lock to prevent concurrent execution from manipulating shared resources? If yes, putting [RelayCommand] is sufficient as by default AllowConcurrentExecutions is set to false.

References: RelayCommand docs

@AmelBawa-msft AmelBawa-msft added Needs-Second Pull request that needs another approval and removed Needs-Second Pull request that needs another approval labels Jul 16, 2024
@krschau krschau merged commit 91ce1ea into main Jul 16, 2024
4 checks passed
@krschau krschau deleted the user/krschau/keyboard branch July 16, 2024 21:14
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.

3 participants