|
@@ -54,12 +54,12 @@ const plugin: JupyterLabPlugin<void> = {
|
|
id: 'jupyter.extensions.shortcuts',
|
|
id: 'jupyter.extensions.shortcuts',
|
|
requires: [ISettingRegistry],
|
|
requires: [ISettingRegistry],
|
|
activate: (app: JupyterLab, settingReqistry: ISettingRegistry): void => {
|
|
activate: (app: JupyterLab, settingReqistry: ISettingRegistry): void => {
|
|
- settingReqistry.load(plugin.id).then(settings => {
|
|
|
|
- let disposables = Private.loadShortcuts(app, settings);
|
|
|
|
|
|
+ const { commands } = app;
|
|
|
|
|
|
|
|
+ settingReqistry.load(plugin.id).then(settings => {
|
|
|
|
+ Private.loadShortcuts(commands, settings);
|
|
settings.changed.connect(() => {
|
|
settings.changed.connect(() => {
|
|
- disposables.dispose();
|
|
|
|
- disposables = Private.loadShortcuts(app, settings);
|
|
|
|
|
|
+ Private.loadShortcuts(commands, settings);
|
|
});
|
|
});
|
|
}).catch((reason: Error) => {
|
|
}).catch((reason: Error) => {
|
|
console.error('Loading shortcut settings failed.', reason.message);
|
|
console.error('Loading shortcut settings failed.', reason.message);
|
|
@@ -79,19 +79,28 @@ export default plugin;
|
|
* A namespace for private module data.
|
|
* A namespace for private module data.
|
|
*/
|
|
*/
|
|
namespace Private {
|
|
namespace Private {
|
|
|
|
+ /**
|
|
|
|
+ * The internal collection of currently loaded shortcuts.
|
|
|
|
+ */
|
|
|
|
+ let disposables: IDisposable;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Load the keyboard shortcuts from settings.
|
|
* Load the keyboard shortcuts from settings.
|
|
*/
|
|
*/
|
|
export
|
|
export
|
|
- function loadShortcuts(app: JupyterLab, settings: ISettingRegistry.ISettings): IDisposable {
|
|
|
|
|
|
+ function loadShortcuts(commands: CommandRegistry, settings: ISettingRegistry.ISettings): void {
|
|
|
|
+ if (disposables) {
|
|
|
|
+ disposables.dispose();
|
|
|
|
+ }
|
|
|
|
+
|
|
const { composite } = settings;
|
|
const { composite } = settings;
|
|
const keys = Object.keys(composite);
|
|
const keys = Object.keys(composite);
|
|
|
|
|
|
- return keys.reduce((acc, val): DisposableSet => {
|
|
|
|
|
|
+ disposables = keys.reduce((acc, val): DisposableSet => {
|
|
const options = normalizeOptions(composite[val]);
|
|
const options = normalizeOptions(composite[val]);
|
|
|
|
|
|
if (options) {
|
|
if (options) {
|
|
- acc.add(app.commands.addKeyBinding(options));
|
|
|
|
|
|
+ acc.add(commands.addKeyBinding(options));
|
|
}
|
|
}
|
|
|
|
|
|
return acc;
|
|
return acc;
|