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

Add commands without shortcuts #14015

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions packages/shortcuts-extension/src/components/ShortcutUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,11 @@ function getShortcutObjects(
settings: ISettingRegistry.ISettings
): { [index: string]: ShortcutObject } {
const shortcuts = settings.composite.shortcuts as ReadonlyJSONArray;
const commands = new Set(external.getAllCommands());

let shortcutObjects: { [index: string]: ShortcutObject } = {};
shortcuts.forEach((shortcut: any) => {
commands.delete(shortcut.command);
let key = shortcut.command + '_' + shortcut.selector;
if (Object.keys(shortcutObjects).indexOf(key) !== -1) {
let currentCount = shortcutObjects[key].numberOfShortcuts;
Expand Down Expand Up @@ -221,6 +224,20 @@ function getShortcutObjects(
shortcutObjects[keyTo].source = 'Custom';
}
});

// Append all commands without a shortcut
commands.forEach(commandName => {
if (commandName.startsWith('__')) {
// Bail early for private commands
return;
}
const shortcut = (shortcutObjects[`${commandName}_`] =
new ShortcutObject());
shortcut.category = commandName.split(':')[0];
shortcut.commandName = commandName;
shortcut.label = external.getLabel(commandName);
});

return shortcutObjects;
}

Expand Down Expand Up @@ -412,6 +429,17 @@ export class ShortcutUI extends React.Component<
}
if (filterCritera !== '') {
shortcuts.sort((a: ShortcutObject, b: ShortcutObject) => {
// First sort if there is keyboard shortcuts or not
const nShortcutA = Math.min(a.numberOfShortcuts, 1);
const nShortcutB = Math.min(b.numberOfShortcuts, 1);

if (nShortcutA < nShortcutB) {
return 1;
} else if (nShortcutA > nShortcutB) {
return -1;
}

// Second sort by user criteria
const compareA: string = a.get(filterCritera);
const compareB: string = b.get(filterCritera);
if (compareA < compareB) {
Expand Down
1 change: 1 addition & 0 deletions packages/shortcuts-extension/src/components/TopNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface ISymbolsProps {}
/** All external actions, setting commands, getting command list ... */
export interface IShortcutUIexternal {
translator: ITranslator;
getAllCommands: () => string[];
getAllShortCutSettings: () => Promise<ISettingRegistry.ISettings>;
removeShortCut: (key: string) => Promise<void>;
createMenu: () => Menu;
Expand Down
1 change: 1 addition & 0 deletions packages/shortcuts-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function getExternalForJupyterLab(
const shortcutPluginLocation = '@jupyterlab/shortcuts-extension:shortcuts';
return {
translator,
getAllCommands: () => commands.listCommands(),
getAllShortCutSettings: () =>
settingRegistry.reload(shortcutPluginLocation),
removeShortCut: (key: string) =>
Expand Down