-
Notifications
You must be signed in to change notification settings - Fork 13
feat: toasts for move/cut/copy and enter on a block #230
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
Merged
gonfunko
merged 2 commits into
RaspberryPiFoundation:main
from
microbit-matt-hillsdon:toast
Apr 25, 2025
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| /** | ||
| * Centralises hints that we show. | ||
| * | ||
| * @license | ||
| * Copyright 2025 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import {WorkspaceSvg, Toast} from 'blockly'; | ||
| import {SHORTCUT_NAMES} from './constants'; | ||
| import {getShortActionShortcut} from './shortcut_formatting'; | ||
|
|
||
| const unconstrainedMoveHintId = 'unconstrainedMoveHint'; | ||
| const constrainedMoveHintId = 'constrainedMoveHint'; | ||
| const copiedHintId = 'copiedHint'; | ||
| const cutHintId = 'cutHint'; | ||
| const helpHintId = 'helpHint'; | ||
|
|
||
| /** | ||
| * Nudge the user to use unconstrained movement. | ||
| * | ||
| * @param workspace Workspace. | ||
| * @param force Set to show it even if previously shown. | ||
| */ | ||
| export function showUnconstrainedMoveHint( | ||
| workspace: WorkspaceSvg, | ||
| force = false, | ||
| ) { | ||
| const enter = getShortActionShortcut(SHORTCUT_NAMES.EDIT_OR_CONFIRM); | ||
| const modifier = navigator.platform.startsWith('Mac') ? '⌥' : 'Ctrl'; | ||
| const message = `Hold ${modifier} and use arrow keys to move freely, then ${enter} to accept the position`; | ||
| Toast.show(workspace, { | ||
| message, | ||
| id: unconstrainedMoveHintId, | ||
| oncePerSession: !force, | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Nudge the user to move a block that's in move mode. | ||
| * | ||
| * @param workspace Workspace. | ||
| */ | ||
| export function showConstrainedMovementHint(workspace: WorkspaceSvg) { | ||
| const enter = getShortActionShortcut(SHORTCUT_NAMES.EDIT_OR_CONFIRM); | ||
| const message = `Use the arrow keys to move, then ${enter} to accept the position`; | ||
| Toast.show(workspace, { | ||
| message, | ||
| id: constrainedMoveHintId, | ||
| oncePerSession: true, | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Clear active move-related hints, if any. | ||
| * | ||
| * @param workspace The workspace. | ||
| */ | ||
| export function clearMoveHints(workspace: WorkspaceSvg) { | ||
| Toast.hide(workspace, constrainedMoveHintId); | ||
| Toast.hide(workspace, unconstrainedMoveHintId); | ||
| } | ||
|
|
||
| /** | ||
| * Nudge the user to paste after a copy. | ||
| * | ||
| * @param workspace Workspace. | ||
| */ | ||
| export function showCopiedHint(workspace: WorkspaceSvg) { | ||
| Toast.show(workspace, { | ||
| message: `Copied. Press ${getShortActionShortcut('paste')} to paste.`, | ||
| duration: 7000, | ||
| id: copiedHintId, | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Nudge the user to paste after a cut. | ||
| * | ||
| * @param workspace Workspace. | ||
| */ | ||
| export function showCutHint(workspace: WorkspaceSvg) { | ||
| Toast.show(workspace, { | ||
| message: `Cut. Press ${getShortActionShortcut('paste')} to paste.`, | ||
| duration: 7000, | ||
| id: cutHintId, | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Clear active paste-related hints, if any. | ||
| * | ||
| * @param workspace The workspace. | ||
| */ | ||
| export function clearPasteHints(workspace: WorkspaceSvg) { | ||
| Toast.hide(workspace, cutHintId); | ||
| Toast.hide(workspace, copiedHintId); | ||
| } | ||
|
|
||
| /** | ||
| * Nudge the user to open the help. | ||
| * | ||
| * @param workspace The workspace. | ||
| */ | ||
| export function showHelpHint(workspace: WorkspaceSvg) { | ||
| const shortcut = getShortActionShortcut('list_shortcuts'); | ||
| const message = `Press ${shortcut} for help on keyboard controls`; | ||
| const id = helpHintId; | ||
| Toast.show(workspace, {message, id}); | ||
| } | ||
|
|
||
| /** | ||
| * Clear the help hint. | ||
| * | ||
| * @param workspace The workspace. | ||
| */ | ||
| export function clearHelpHint(workspace: WorkspaceSvg) { | ||
| // TODO: We'd like to do this in MakeCode too as we override. | ||
| // Could have an option for showing help in the plugin? | ||
| Toast.hide(workspace, helpHintId); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.