Skip to content

Add PrioritizedIntents to support multiple shortcut configurations - #72560

Merged
Piinks merged 8 commits into
flutter:masterfrom
Piinks:webSpacePage
Jan 5, 2021
Merged

Piinks merged 8 commits into
flutter:masterfrom
Piinks:webSpacePage

Conversation

@Piinks

@Piinks Piinks commented Dec 17, 2020 •

Copy link
Copy Markdown
Contributor

Description

This adds a new Intent - PrioritizedIntents
This will allow for multiple Intents to be associated with a single LogicalKeySet, so multiple Shortcuts can be evaluated.

For example - the web platform expects that, in the right context, the spacebar will scroll a scroll view. This has not been possible because the spacebar also serves as a shortcut to activate switches and buttons.

In a PrioritizedAction, the listed Intents will be evaluated such that the right Action will be invoked. In our web case, the ActivateIntent will be evaluated first, followed by the ScrollIntent. So if there were a Checkbox inside of a ScrollView, the space bar shortcut could scroll the view or activate the checkbox, depending on the location of the primaryFocus. The test case here shows this example.

Related Issues

Fixes #43694

Tests

Shortcuts support multiple intents

Checklist

Before you create this PR, confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.

@Piinks Piinks added c: new feature Nothing broken; request for a new capability framework flutter/packages/flutter repository. See also f: labels. platform-web Web applications specifically a: desktop Running on desktop f: focus Focus traversal, gaining or losing focus labels Dec 17, 2020
@google-cla google-cla Bot added the cla: yes label Dec 17, 2020
@Piinks

Piinks commented Dec 17, 2020

Copy link
Copy Markdown
Contributor Author

@gspencergoog perhaps for discussing after the holidays, this is what I had in mind for the multi-Intent we mentioned earlier this week. :)

@gspencergoog

Copy link
Copy Markdown
Contributor

@Piinks This is super cool! I say write the test and ship it!

@Piinks Piinks added the f: scrolling Viewports, list views, slivers, etc. label Jan 5, 2021
@Piinks Piinks changed the title [WIP] Add PrioritizedIntents Add PrioritizedIntents to support multiple shortcut configurations Jan 5, 2021
Comment thread packages/flutter/lib/src/widgets/actions.dart Outdated
Comment thread packages/flutter/lib/src/widgets/actions.dart Outdated
@Piinks
Piinks marked this pull request as ready for review January 5, 2021 20:16
@Piinks
Piinks requested a review from gspencergoog January 5, 2021 20:16

@gspencergoog gspencergoog left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

32384589-a60f0e74-c078-11e7-9bc1-e5b5287aea9d

Comment thread packages/flutter/lib/src/widgets/actions.dart
Comment thread packages/flutter/lib/src/widgets/actions.dart Outdated
Comment thread packages/flutter/lib/src/widgets/actions.dart Outdated
Comment thread packages/flutter/lib/src/widgets/actions.dart
Comment thread packages/flutter/lib/src/widgets/actions.dart
@Piinks
Piinks merged commit 3fd3447 into flutter:master Jan 5, 2021
@devanflores

devanflores commented Jan 18, 2021 •

Copy link
Copy Markdown

@Piinks Is there any way to disable this functionality through an option e.g. prevent spacebar from scrolling with a boolean?

@Piinks

Piinks commented Jan 19, 2021

Copy link
Copy Markdown
Contributor Author

@Piinks Is there any way to disable this functionality through an option e.g. prevent spacebar from scrolling with a boolean?

Hey @devanflores you can provide your own shortcuts to MaterialApp.shortcuts to override the default shortcuts.
I think in the case you mentioned in #43694, you might also be able to put a Shortcut around your TextField that will override the top level Shortcuts. I have not tried it out yet.

@gspencergoog

Copy link
Copy Markdown
Contributor

@devanflores you can override any shortcut binding by placing a "Shortcuts" widget above the widgets you would like to override it for (or at the top of your app, as a child of the MaterialApp/CupertinoApp widget), defining a different shortcut binding for the same keys. You can also disable it entirely by binding it to a DoNothingIntent().

So, like this:

Widget build(BuildContext context) {
  return Shortcuts(
    shortcuts: <LogicalKeySet, Intent> {
      LogicalKeySet(LogicalKeyboardKey.space): DoNothingIntent(),
    },
	child: child,
  );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktop Running on desktop c: new feature Nothing broken; request for a new capability f: focus Focus traversal, gaining or losing focus f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. platform-web Web applications specifically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[web] Add support for spacebar Shortcut to include ScrollIntent

3 participants