Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/actions/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Gesture,
ShortcutRegistry,
Events,
Msg,
utils as blocklyUtils,
clipboard,
ICopyData,
Expand Down Expand Up @@ -104,7 +105,8 @@ export class Clipboard {
*/
private registerCutContextMenuAction() {
const cutAction: ContextMenuRegistry.RegistryItem = {
displayText: (scope) => `Cut (${getShortActionShortcut('cut')})`,
displayText: (scope) =>
Msg['CUT_SHORTCUT'].replace('%1', getShortActionShortcut('cut')),
preconditionFn: (scope) => {
const ws = scope.block?.workspace;
if (!ws) return 'hidden';
Expand Down Expand Up @@ -199,7 +201,8 @@ export class Clipboard {
*/
private registerCopyContextMenuAction() {
const copyAction: ContextMenuRegistry.RegistryItem = {
displayText: (scope) => `Copy (${getShortActionShortcut('copy')})`,
displayText: (scope) =>
Msg['COPY_SHORTCUT'].replace('%1', getShortActionShortcut('copy')),
preconditionFn: (scope) => {
const ws = scope.block?.workspace;
if (!ws) return 'hidden';
Expand Down Expand Up @@ -304,7 +307,8 @@ export class Clipboard {
*/
private registerPasteContextMenuAction() {
const pasteAction: ContextMenuRegistry.RegistryItem = {
displayText: (scope) => `Paste (${getShortActionShortcut('paste')})`,
displayText: (scope) =>
Msg['PASTE_SHORTCUT'].replace('%1', getShortActionShortcut('paste')),
preconditionFn: (scope: ContextMenuRegistry.Scope) => {
let block;
if (scope.focusedNode instanceof Blockly.Block) {
Expand Down
7 changes: 5 additions & 2 deletions src/actions/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import {
ContextMenuRegistry,
Gesture,
Msg,
ShortcutRegistry,
utils as BlocklyUtils,
LineCursor,
} from 'blockly';
import {getShortActionShortcut} from '../shortcut_formatting';
import * as Constants from '../constants';
import type {WorkspaceSvg} from 'blockly';
import {Navigation} from '../navigation';
Expand Down Expand Up @@ -102,16 +104,17 @@ export class DeleteAction {

const deleteItem: ContextMenuRegistry.RegistryItem = {
displayText: (scope) => {
const shortcut = getShortActionShortcut(this.deleteShortcutName);
if (!this.oldContextMenuItem) {
return 'Delete block (Del)';
return Msg['DELETE_BLOCK'].replace('%1', shortcut);
}

type DisplayTextFn = (p1: ContextMenuRegistry.Scope) => string;
// Use the original item's text, which is dynamic based on the number
// of blocks that will be deleted.
const oldDisplayText = this.oldContextMenuItem
.displayText as DisplayTextFn;
return oldDisplayText(scope) + ' (Del)';
return oldDisplayText(scope) + ` (${shortcut})`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will this localize for RTL correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, but this is kind of a hack in the first place so I think that's acceptable for now.

},
preconditionFn: (scope, menuOpenEvent: Event) => {
const ws = scope.block?.workspace;
Expand Down
9 changes: 7 additions & 2 deletions src/actions/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

import {ContextMenuRegistry, LineCursor} from 'blockly';
import {ContextMenuRegistry, LineCursor, Msg} from 'blockly';
import {Navigation} from 'src/navigation';
import {getShortActionShortcut} from '../shortcut_formatting';
import * as Constants from '../constants';

/**
* Action to edit a block. This just moves the cursor to the first
Expand Down Expand Up @@ -50,7 +52,10 @@ export class EditAction {
*/
private registerContextMenuAction() {
const editAboveItem: ContextMenuRegistry.RegistryItem = {
displayText: 'Edit Block contents (→︎)',
displayText: Msg['EDIT_BLOCK_CONTENTS'].replace(
'%1',
getShortActionShortcut(Constants.SHORTCUT_NAMES.RIGHT),
),
preconditionFn: (scope: ContextMenuRegistry.Scope, menuOpenEvent) => {
if (menuOpenEvent instanceof PointerEvent) return 'hidden';
const workspace = scope.block?.workspace;
Expand Down
1 change: 1 addition & 0 deletions src/actions/enter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import {
Events,
Msg,

Check warning on line 9 in src/actions/enter.ts

View workflow job for this annotation

GitHub Actions / Eslint check

'Msg' is defined but never used
ShortcutRegistry,
utils as BlocklyUtils,
getFocusManager,
Expand Down
7 changes: 6 additions & 1 deletion src/actions/insert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

import {
ContextMenuRegistry,
Msg,
ShortcutRegistry,
utils as BlocklyUtils,
} from 'blockly';
import {getShortActionShortcut} from '../shortcut_formatting';
import * as Constants from '../constants';
import type {WorkspaceSvg} from 'blockly';
import {Navigation} from '../navigation';
Expand Down Expand Up @@ -69,7 +71,10 @@ export class InsertAction {
private registerContextMenuAction() {
const insertAboveItem: ContextMenuRegistry.RegistryItem = {
displayText: () => {
return 'Insert Block (I)';
return Msg['INSERT_BLOCK'].replace(
'%1',
getShortActionShortcut(this.insertShortcutName),
);
},
preconditionFn: (
scope: ContextMenuRegistry.Scope,
Expand Down
Loading
Loading