Skip to content
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

Allow platform aware key shortcuts #7589

Merged
merged 14 commits into from Dec 23, 2019
11 changes: 8 additions & 3 deletions packages/coreutils/src/settingregistry.ts
Expand Up @@ -13,6 +13,8 @@ import {
ReadonlyJSONValue
} from '@phosphor/coreutils';

import { normalizeKeys } from '@phosphor/commands';

import { DisposableDelegate, IDisposable } from '@phosphor/disposable';

import { ISignal, Signal } from '@phosphor/signaling';
Expand Down Expand Up @@ -880,11 +882,14 @@ export namespace SettingRegistry {

// If a user shortcut collides with another user shortcut warn and filter.
user = user.filter(shortcut => {
const keys = shortcut.keys.join(RECORD_SEPARATOR);
const keys = normalizeKeys(shortcut).join(RECORD_SEPARATOR);
const { selector } = shortcut;

if (!keys) {
console.warn('Shortcut skipped because `keys` are [""].', shortcut);
console.warn(
'Shortcut skipped because `keys` and platform keys are [""].',
groutr marked this conversation as resolved.
Show resolved Hide resolved
shortcut
);
return false;
}
if (!(keys in memo)) {
Expand All @@ -904,7 +909,7 @@ export namespace SettingRegistry {
// out too (this includes shortcuts that are disabled by user preferences).
defaults = defaults.filter(shortcut => {
const { disabled } = shortcut;
const keys = shortcut.keys.join(RECORD_SEPARATOR);
const keys = normalizeKeys(shortcut).join(RECORD_SEPARATOR);

if (disabled || !keys) {
return false;
Expand Down
13 changes: 12 additions & 1 deletion packages/shortcuts-extension/schema/shortcuts.json
Expand Up @@ -22,7 +22,18 @@
"command": { "type": "string" },
"keys": {
"items": { "type": "string" },
"minItems": 1,
"type": "array"
},
"winKeys": {
"items": { "type": "string" },
"type": "array"
},
"macKeys": {
"items": { "type": "string" },
"type": "array"
},
"linuxKeys": {
"items": { "type": "string" },
"type": "array"
},
"selector": { "type": "string" }
Expand Down