Skip to content

Commit

Permalink
Merge pull request #7589 from groutr/platformshortcuts
Browse files Browse the repository at this point in the history
Allow platform aware key shortcuts
  • Loading branch information
jasongrout committed Dec 23, 2019
2 parents ecfe2cb + fb2a273 commit 5167b6e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
25 changes: 20 additions & 5 deletions packages/coreutils/src/settingregistry.ts
Expand Up @@ -5,6 +5,8 @@ import Ajv from 'ajv';

import * as json from 'json5';

import { CommandRegistry } from '@lumino/commands';

import {
JSONExt,
JSONObject,
Expand Down Expand Up @@ -913,11 +915,16 @@ 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 = CommandRegistry.normalizeKeys(shortcut).join(
RECORD_SEPARATOR
);
const { selector } = shortcut;

if (!keys) {
console.warn('Shortcut skipped because `keys` are [""].', shortcut);
console.warn(
'Skipping this shortcut because there are no actionable keys on this platform',
shortcut
);
return false;
}
if (!(keys in memo)) {
Expand All @@ -928,7 +935,10 @@ export namespace SettingRegistry {
return true;
}

console.warn('Shortcut skipped due to collision.', shortcut);
console.warn(
'Skipping this shortcut because it collides with another shortcut.',
shortcut
);
return false;
});

Expand All @@ -937,7 +947,9 @@ 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 = CommandRegistry.normalizeKeys(shortcut).join(
RECORD_SEPARATOR
);

if (disabled || !keys) {
return false;
Expand All @@ -955,7 +967,10 @@ export namespace SettingRegistry {

// Only warn if a default shortcut collides with another default shortcut.
if (memo[keys][selector]) {
console.warn('Shortcut skipped due to collision.', shortcut);
console.warn(
'Skipping this shortcut because it collides with another shortcut.',
shortcut
);
}

return false;
Expand Down
14 changes: 12 additions & 2 deletions packages/shortcuts-extension/schema/shortcuts.json
Expand Up @@ -8,7 +8,6 @@
"additionalProperties": false,
"properties": {
"shortcuts": {
"title": "Keyboard Shortcuts",
"description": "The list of keyboard shortcuts.",
"items": { "$ref": "#/definitions/shortcut" },
"type": "array",
Expand All @@ -22,7 +21,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
12 changes: 5 additions & 7 deletions packages/shortcuts-extension/src/index.ts
Expand Up @@ -71,10 +71,8 @@ const shortcuts: JupyterFrontEndPlugin<void> = {
})
.reduce((acc, val) => acc.concat(val), [])
.sort((a, b) => a.command.localeCompare(b.command));
schema.properties!.shortcuts.title =
'List of Commands (followed by shortcuts)';

const disableShortcutInstructions = `Note: To disable a system default shortcut,
schema.properties!.shortcuts.description = `Note: To disable a system default shortcut,
copy it to User Preferences and add the
"disabled" key, for example:
{
Expand All @@ -84,12 +82,12 @@ copy it to User Preferences and add the
],
"selector": "body",
"disabled": true
}`;
schema.properties!.shortcuts.description = `${commands}
}
${disableShortcutInstructions}
List of commands followed by keyboard shortcuts:
${commands}
List of Keyboard Shortcuts`;
List of keyboard shortcuts:`;
}

registry.pluginChanged.connect(async (sender, plugin) => {
Expand Down

0 comments on commit 5167b6e

Please sign in to comment.