-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat: Add keyboard shortcut to perform an action on the currently focused element #9673
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 3 commits
6cb7ed6
cc4f410
44a6acc
5ead311
6c15742
6241f8d
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 |
|---|---|---|
|
|
@@ -6,11 +6,15 @@ | |
|
|
||
| import {Msg} from './msg.js'; | ||
| import {Toast} from './toast.js'; | ||
| import {getShortActionShortcut} from './utils/shortcut_formatting.js'; | ||
| import * as userAgent from './utils/useragent.js'; | ||
| import type {WorkspaceSvg} from './workspace_svg.js'; | ||
|
|
||
| const unconstrainedMoveHintId = 'unconstrainedMoveHint'; | ||
| const constrainedMoveHintId = 'constrainedMoveHint'; | ||
| const helpHintId = 'helpHint'; | ||
| const blockNavigationHintId = 'blockNavigationHint'; | ||
| const workspaceNavigationHintId = 'workspaceNavigationHint'; | ||
|
|
||
| /** | ||
| * Nudge the user to use unconstrained movement. | ||
|
|
@@ -62,3 +66,37 @@ export function clearMoveHints(workspace: WorkspaceSvg) { | |
| Toast.hide(workspace, constrainedMoveHintId); | ||
| Toast.hide(workspace, unconstrainedMoveHintId); | ||
| } | ||
|
|
||
| /** | ||
| * Nudge the user to open the help. | ||
| * | ||
| * @param workspace The workspace. | ||
| */ | ||
| export function showHelpHint(workspace: WorkspaceSvg) { | ||
| const shortcut = getShortActionShortcut('list_shortcuts'); | ||
|
Contributor
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. Should we handle the potential case where
Contributor
Author
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. That is a possibility, I'm not sure how we might helpfully handle it though. End users wouldn't be able to do anything about it, I suppose we could just not show the toast? Or did you have something else in mind?
Contributor
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 think it's reasonable that if the shortcut isn't available because it was unregistered, we could just return early and not show the toast. No toast is better than one that says "Press for help on keyboard controls". The only other option I can think of would be a fallback string that just says "invalid action" or something if we don't have a shortcut to suggest for help.
Contributor
Author
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. Added an early return in that case. I also disabled the test as it now fails since the shortcut to show the list of shortcuts doesn't yet exist. |
||
| const message = Msg['HELP_PROMPT'].replace('%1', shortcut); | ||
| const id = helpHintId; | ||
| Toast.show(workspace, {message, id}); | ||
| } | ||
|
|
||
| /** | ||
| * Tell the user how to navigate inside blocks. | ||
| * | ||
| * @param workspace The workspace. | ||
| */ | ||
| export function showBlockNavigationHint(workspace: WorkspaceSvg) { | ||
| const message = Msg['KEYBOARD_NAV_BLOCK_NAVIGATION_HINT']; | ||
| const id = blockNavigationHintId; | ||
| Toast.show(workspace, {message, id}); | ||
| } | ||
|
|
||
| /** | ||
| * Tell the user how to navigate inside the workspace. | ||
| * | ||
| * @param workspace The workspace. | ||
| */ | ||
| export function showWorkspaceNavigationHint(workspace: WorkspaceSvg) { | ||
| const message = Msg['KEYBOARD_NAV_WORKSPACE_NAVIGATION_HINT']; | ||
| const id = workspaceNavigationHintId; | ||
| Toast.show(workspace, {message, id}); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.