Skip to content

Commit 25d595f

Browse files
Rebase and update toast branch
We now use the Toast class in Blockly core to show and hide toasts.
1 parent 86c7113 commit 25d595f

File tree

4 files changed

+33
-204
lines changed

4 files changed

+33
-204
lines changed

src/actions/clipboard.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ import type {BlockSvg, WorkspaceSvg} from 'blockly';
1919
import {Navigation} from '../navigation';
2020
import {getShortActionShortcut} from '../shortcut_formatting';
2121
import * as Blockly from 'blockly';
22-
import {toast} from '../toast';
23-
import {clearPasteHints, showCopiedHint} from '../hints';
22+
import {clearPasteHints, showCopiedHint, showCutHint} from '../hints';
2423

2524
const KeyCodes = blocklyUtils.KeyCodes;
2625
const createSerializedKey = ShortcutRegistry.registry.createSerializedKey.bind(
@@ -170,6 +169,10 @@ export class Clipboard {
170169
if (cursor instanceof LineCursor) cursor.preDelete(sourceBlock);
171170
sourceBlock.checkAndDelete();
172171
if (cursor instanceof LineCursor) cursor.postDelete();
172+
const cut = !!this.copyData;
173+
if (cut) {
174+
showCutHint(workspace);
175+
}
173176
return true;
174177
}
175178

src/hints.ts

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
* SPDX-License-Identifier: Apache-2.0
77
*/
88

9-
import {WorkspaceSvg} from 'blockly';
9+
import {WorkspaceSvg, Toast} from 'blockly';
1010
import {SHORTCUT_NAMES} from './constants';
1111
import {getShortActionShortcut} from './shortcut_formatting';
12-
import {clearToast, toast} from './toast';
1312

1413
const unconstrainedMoveHintId = 'unconstrainedMoveHint';
1514
const constrainedMoveHintId = 'constrainedMoveHint';
1615
const copiedHintId = 'copiedHint';
16+
const cutHintId = 'cutHint';
1717
const helpHintId = 'helpHint';
1818

1919
/**
@@ -29,7 +29,7 @@ export function showUnconstrainedMoveHint(
2929
const enter = getShortActionShortcut(SHORTCUT_NAMES.EDIT_OR_CONFIRM);
3030
const modifier = navigator.platform.startsWith('Mac') ? '⌥' : 'Ctrl';
3131
const message = `Hold ${modifier} and use arrow keys to move freely, then ${enter} to accept the position`;
32-
toast(workspace, {
32+
Toast.show(workspace, {
3333
message,
3434
id: unconstrainedMoveHintId,
3535
oncePerSession: !force,
@@ -44,7 +44,11 @@ export function showUnconstrainedMoveHint(
4444
export function showConstrainedMovementHint(workspace: WorkspaceSvg) {
4545
const enter = getShortActionShortcut(SHORTCUT_NAMES.EDIT_OR_CONFIRM);
4646
const message = `Use the arrow keys to move, then ${enter} to accept the position`;
47-
toast(workspace, {message, id: constrainedMoveHintId, oncePerSession: true});
47+
Toast.show(workspace, {
48+
message,
49+
id: constrainedMoveHintId,
50+
oncePerSession: true,
51+
});
4852
}
4953

5054
/**
@@ -53,8 +57,8 @@ export function showConstrainedMovementHint(workspace: WorkspaceSvg) {
5357
* @param workspace The workspace.
5458
*/
5559
export function clearMoveHints(workspace: WorkspaceSvg) {
56-
clearToast(workspace, constrainedMoveHintId);
57-
clearToast(workspace, unconstrainedMoveHintId);
60+
Toast.hide(workspace, constrainedMoveHintId);
61+
Toast.hide(workspace, unconstrainedMoveHintId);
5862
}
5963

6064
/**
@@ -63,21 +67,34 @@ export function clearMoveHints(workspace: WorkspaceSvg) {
6367
* @param workspace Workspace.
6468
*/
6569
export function showCopiedHint(workspace: WorkspaceSvg) {
66-
toast(workspace, {
70+
Toast.show(workspace, {
6771
message: `Copied. Press ${getShortActionShortcut('paste')} to paste.`,
6872
duration: 7000,
6973
id: copiedHintId,
7074
});
7175
}
7276

77+
/**
78+
* Nudge the user to paste after a cut.
79+
*
80+
* @param workspace Workspace.
81+
*/
82+
export function showCutHint(workspace: WorkspaceSvg) {
83+
Toast.show(workspace, {
84+
message: `Cut. Press ${getShortActionShortcut('paste')} to paste.`,
85+
duration: 7000,
86+
id: cutHintId,
87+
});
88+
}
89+
7390
/**
7491
* Clear active paste-related hints, if any.
7592
*
7693
* @param workspace The workspace.
7794
*/
7895
export function clearPasteHints(workspace: WorkspaceSvg) {
79-
// TODO: cut?
80-
clearToast(workspace, copiedHintId);
96+
Toast.hide(workspace, cutHintId);
97+
Toast.hide(workspace, copiedHintId);
8198
}
8299

83100
/**
@@ -89,7 +106,7 @@ export function showHelpHint(workspace: WorkspaceSvg) {
89106
const shortcut = getShortActionShortcut('list_shortcuts');
90107
const message = `Press ${shortcut} for help on keyboard controls`;
91108
const id = helpHintId;
92-
toast(workspace, {message, id});
109+
Toast.show(workspace, {message, id});
93110
}
94111

95112
/**
@@ -100,5 +117,5 @@ export function showHelpHint(workspace: WorkspaceSvg) {
100117
export function clearHelpHint(workspace: WorkspaceSvg) {
101118
// TODO: We'd like to do this in MakeCode too as we override.
102119
// Could have an option for showing help in the plugin?
103-
clearToast(workspace, helpHintId);
120+
Toast.hide(workspace, helpHintId);
104121
}

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import * as Blockly from 'blockly/core';
88
import {NavigationController} from './navigation_controller';
99
import {getFlyoutElement, getToolboxElement} from './workspace_utilities';
1010
import {enableBlocksOnDrag} from './disabled_blocks';
11-
import {clearHelpHint} from './hints';
1211

1312
/** Options object for KeyboardNavigation instances. */
1413
export interface NavigationOptions {

src/toast.ts

Lines changed: 0 additions & 190 deletions
This file was deleted.

0 commit comments

Comments
 (0)