Skip to content
Open
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
37 changes: 11 additions & 26 deletions core/shortcut_items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,7 @@ function isCuttable(focused: IFocusableNode): boolean {
*/
export function registerCopy() {
const ctrlC = ShortcutRegistry.registry.createSerializedKey(KeyCodes.C, [
KeyCodes.CTRL,
]);
const metaC = ShortcutRegistry.registry.createSerializedKey(KeyCodes.C, [
KeyCodes.META,
KeyCodes.CTRL_CMD,
]);

const copyShortcut: KeyboardShortcut = {
Expand Down Expand Up @@ -179,7 +176,7 @@ export function registerCopy() {
: undefined;
return !!clipboard.copy(focused, copyCoords);
},
keyCodes: [ctrlC, metaC],
keyCodes: [ctrlC],
};
ShortcutRegistry.registry.register(copyShortcut);
}
Expand All @@ -189,10 +186,7 @@ export function registerCopy() {
*/
export function registerCut() {
const ctrlX = ShortcutRegistry.registry.createSerializedKey(KeyCodes.X, [
KeyCodes.CTRL,
]);
const metaX = ShortcutRegistry.registry.createSerializedKey(KeyCodes.X, [
KeyCodes.META,
KeyCodes.CTRL_CMD,
]);

const cutShortcut: KeyboardShortcut = {
Expand Down Expand Up @@ -224,7 +218,7 @@ export function registerCut() {
}
return !!copyData;
},
keyCodes: [ctrlX, metaX],
keyCodes: [ctrlX],
};

ShortcutRegistry.registry.register(cutShortcut);
Expand All @@ -235,10 +229,7 @@ export function registerCut() {
*/
export function registerPaste() {
const ctrlV = ShortcutRegistry.registry.createSerializedKey(KeyCodes.V, [
KeyCodes.CTRL,
]);
const metaV = ShortcutRegistry.registry.createSerializedKey(KeyCodes.V, [
KeyCodes.META,
KeyCodes.CTRL_CMD,
]);

const pasteShortcut: KeyboardShortcut = {
Expand Down Expand Up @@ -309,7 +300,7 @@ export function registerPaste() {
const centerCoords = new Coordinate(left + width / 2, top + height / 2);
return !!clipboard.paste(copyData, targetWorkspace, centerCoords);
},
keyCodes: [ctrlV, metaV],
keyCodes: [ctrlV],
};

ShortcutRegistry.registry.register(pasteShortcut);
Expand All @@ -320,10 +311,7 @@ export function registerPaste() {
*/
export function registerUndo() {
const ctrlZ = ShortcutRegistry.registry.createSerializedKey(KeyCodes.Z, [
KeyCodes.CTRL,
]);
const metaZ = ShortcutRegistry.registry.createSerializedKey(KeyCodes.Z, [
KeyCodes.META,
KeyCodes.CTRL_CMD,
]);

const undoShortcut: KeyboardShortcut = {
Expand All @@ -342,7 +330,7 @@ export function registerUndo() {
e.preventDefault();
return true;
},
keyCodes: [ctrlZ, metaZ],
keyCodes: [ctrlZ],
};
ShortcutRegistry.registry.register(undoShortcut);
}
Expand All @@ -353,13 +341,10 @@ export function registerUndo() {
*/
export function registerRedo() {
const ctrlShiftZ = ShortcutRegistry.registry.createSerializedKey(KeyCodes.Z, [
KeyCodes.CTRL,
KeyCodes.SHIFT,
]);
const metaShiftZ = ShortcutRegistry.registry.createSerializedKey(KeyCodes.Z, [
KeyCodes.META,
KeyCodes.CTRL_CMD,
KeyCodes.SHIFT,
]);

// Ctrl-y is redo in Windows. Command-y is never valid on Macs.
const ctrlY = ShortcutRegistry.registry.createSerializedKey(KeyCodes.Y, [
KeyCodes.CTRL,
Expand All @@ -381,7 +366,7 @@ export function registerRedo() {
e.preventDefault();
return true;
},
keyCodes: [ctrlShiftZ, metaShiftZ, ctrlY],
keyCodes: [ctrlShiftZ, ctrlY],
};
ShortcutRegistry.registry.register(redoShortcut);
}
Expand Down
6 changes: 6 additions & 0 deletions core/utils/keycodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

import * as userAgent from '../utils/useragent.js';

// Former goog.module ID: Blockly.utils.KeyCodes

/* eslint-disable @typescript-eslint/no-duplicate-enum-values */
Expand Down Expand Up @@ -151,4 +153,8 @@ export enum KeyCodes {
// indicates a hardware/bios problem.
// http://en.community.dell.com/support-forums/laptop/f/3518/p/19285957/19523128.aspx
PHANTOM = 255,

// The primary modifier key on the current platform, i.e. Command on Apple
// platforms and Control elsewhere.
CTRL_CMD = userAgent.MAC || userAgent.IPHONE || userAgent.IPAD ? 91 : 17,
}
Loading
Loading