Skip to content

Commit 7a297ca

Browse files
fix: toast shortcut formatting, styling, timings
- format shortcuts as per the menu - don't use blocks font, it looks very odd in MakeCode - tweak sizing to limit text not overall width - increase timeouts based on user researcher feedback
1 parent 0e4800d commit 7a297ca

File tree

4 files changed

+28
-31
lines changed

4 files changed

+28
-31
lines changed

src/actions/clipboard.ts

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import {
1414
import * as Constants from '../constants';
1515
import type {BlockSvg, Workspace, WorkspaceSvg} from 'blockly';
1616
import {Navigation} from '../navigation';
17-
import { toast } from '../toast';
17+
import {toast} from '../toast';
18+
import {formatMetaShortcut} from '../shortcut_formatting';
1819

1920
const KeyCodes = blocklyUtils.KeyCodes;
2021
const createSerializedKey = ShortcutRegistry.registry.createSerializedKey.bind(
@@ -108,7 +109,7 @@ export class Clipboard {
108109
*/
109110
private registerCutContextMenuAction() {
110111
const cutAction: ContextMenuRegistry.RegistryItem = {
111-
displayText: (scope) => `Cut (${this.getPlatformPrefix()}X)`,
112+
displayText: (scope) => `Cut (${formatMetaShortcut('X')})`,
112113
preconditionFn: (scope) => {
113114
const ws = scope.block?.workspace;
114115
if (!ws) return 'hidden';
@@ -200,7 +201,7 @@ export class Clipboard {
200201
*/
201202
private registerCopyContextMenuAction() {
202203
const copyAction: ContextMenuRegistry.RegistryItem = {
203-
displayText: (scope) => `Copy (${this.getPlatformPrefix()}C)`,
204+
displayText: (scope) => `Copy (${formatMetaShortcut('C')})`,
204205
preconditionFn: (scope) => {
205206
const ws = scope.block?.workspace;
206207
if (!ws) return 'hidden';
@@ -276,8 +277,8 @@ export class Clipboard {
276277
this.copyWorkspace = sourceBlock.workspace;
277278
if (this.copyData) {
278279
toast(workspace, {
279-
message: `Copied. Press ${navigator.platform.startsWith('Mac') ? '⌘' : 'Ctrl'} + V to paste.`,
280-
duration: 3000,
280+
message: `Copied. Press ${formatMetaShortcut("V")} to paste.`,
281+
duration: 4500,
281282
});
282283
}
283284
return !!this.copyData;
@@ -308,7 +309,7 @@ export class Clipboard {
308309
*/
309310
private registerPasteContextMenuAction() {
310311
const pasteAction: ContextMenuRegistry.RegistryItem = {
311-
displayText: (scope) => `Paste (${this.getPlatformPrefix()}V)`,
312+
displayText: (scope) => `Paste (${formatMetaShortcut('V')})`,
312313
preconditionFn: (scope) => {
313314
const ws = scope.block?.workspace;
314315
if (!ws) return 'hidden';
@@ -359,16 +360,4 @@ export class Clipboard {
359360
: this.copyWorkspace;
360361
return this.navigation.paste(this.copyData, pasteWorkspace);
361362
}
362-
363-
/**
364-
* Check the platform and return a prefix for the keyboard shortcut.
365-
* TODO: https://github.com/google/blockly-keyboard-experimentation/issues/155
366-
* This will eventually be the responsibility of the action code ib
367-
* Blockly core.
368-
*
369-
* @returns A platform-appropriate string for the meta key.
370-
*/
371-
private getPlatformPrefix() {
372-
return navigator.platform.startsWith('Mac') ? '⌘' : 'Ctrl + ';
373-
}
374363
}

src/navigation.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
} from './flyout_cursor';
2020
import {PassiveFocus} from './passive_focus';
2121
import {toast} from './toast';
22+
import { formatMetaShortcut } from './shortcut_formatting';
2223

2324
/**
2425
* Class that holds all methods necessary for keyboard navigation to work.
@@ -1271,9 +1272,9 @@ export class Navigation {
12711272
} else if (nodeType === Blockly.ASTNode.types.BLOCK) {
12721273
const block = curNode.getLocation() as Blockly.Block;
12731274
if (!tryShowFullBlockFieldEditor(block)) {
1274-
const metaKey = navigator.platform.startsWith('Mac') ? '⌘' : 'Ctrl';
1275-
const canMoveInHint = `Press right arrow to move in or ${metaKey} + Enter for more options`;
1276-
const genericHint = `Press ${metaKey} + Enter for options`;
1275+
const shortcut = formatMetaShortcut("Enter")
1276+
const canMoveInHint = `Press right arrow to move in or ${shortcut} for more options`;
1277+
const genericHint = `Press ${shortcut} for options`;
12771278
const message =
12781279
curNode.in()?.getSourceBlock() === block
12791280
? canMoveInHint

src/shortcut_formatting.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Check the platform and return a prefix for the keyboard shortcut.
3+
* TODO: https://github.com/google/blockly-keyboard-experimentation/issues/155
4+
* This will eventually be the responsibility of the action code ib
5+
* Blockly core.
6+
*
7+
* @param key The key to press in combination with Ctrl of Command.
8+
* @returns A platform-appropriate string for the meta key.
9+
*/
10+
export function formatMetaShortcut(key: string) {
11+
return `${navigator.platform.startsWith('Mac') ? '⌘' : 'Ctrl + '}${key}`;
12+
}

src/toast.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,17 @@ export interface ToastOptions {
3131
* @param options Options.
3232
*/
3333
export function toast(workspace: WorkspaceSvg, options: ToastOptions): void {
34-
const {message, duration = 5000} = options;
34+
const {message, duration = 7500} = options;
3535
const className = 'blocklyToast';
3636
workspace.getInjectionDiv().querySelector(`.${className}`)?.remove();
3737

3838
const toast = document.createElement('div');
3939
toast.className = className;
4040
toast.setAttribute('role', 'status');
4141
toast.setAttribute('aria-live', 'polite');
42-
const {
43-
FIELD_TEXT_FONTWEIGHT: fontWeight,
44-
FIELD_TEXT_FONTFAMILY: fontFamily,
45-
FIELD_TEXT_FONTSIZE: fontSizePt,
46-
} = workspace.getRenderer().getConstants();
4742
assignStyle(toast, {
48-
fontFamily,
49-
fontWeight,
50-
fontSize: `${fontSizePt}pt`,
43+
fontSize: '1.2rem',
5144
position: 'absolute',
52-
maxWidth: '20em',
5345
bottom: '2rem',
5446
right: '-50rem',
5547
padding: '1rem',
@@ -71,6 +63,9 @@ export function toast(workspace: WorkspaceSvg, options: ToastOptions): void {
7163
}),
7264
);
7365
const messageElement = toast.appendChild(document.createElement('div'));
66+
assignStyle(messageElement, {
67+
maxWidth: '18rem',
68+
});
7469
messageElement.innerText = message;
7570
const closeButton = toast.appendChild(document.createElement('button'));
7671
assignStyle(closeButton, {

0 commit comments

Comments
 (0)