Browse Source

Fix scope bug in setting registry transform.

Afshin Darian 6 years ago
parent
commit
ab5c7710f6

+ 2 - 4
packages/coreutils/src/settingregistry.ts

@@ -619,11 +619,10 @@ export class SettingRegistry {
    */
   load(plugin: string): Promise<ISettingRegistry.ISettings> {
     const plugins = this._plugins;
-    const transform = this._transform;
 
     // If the plugin exists, resolve.
     if (plugin in plugins) {
-      return transform(plugins[plugin]);
+      return this._transform(plugins[plugin]);
     }
 
     // If the plugin needs to be loaded from the data connector, fetch.
@@ -640,14 +639,13 @@ export class SettingRegistry {
    */
   reload(plugin: string): Promise<ISettingRegistry.ISettings> {
     const plugins = this._plugins;
-    const transform = this._transform;
 
     // If the plugin needs to be loaded from the connector, fetch.
     return this.connector.fetch(plugin).then(data => {
       this._load(data);
       this._pluginChanged.emit(plugin);
 
-      return transform(plugins[plugin]);
+      return this._transform(plugins[plugin]);
     });
   }
 

+ 12 - 3
packages/shortcuts-extension/src/index.ts

@@ -3,7 +3,7 @@
 
 import { JupyterLab, JupyterLabPlugin } from '@jupyterlab/application';
 
-import { ISettingRegistry } from '@jupyterlab/coreutils';
+import { ISettingRegistry, Settings } from '@jupyterlab/coreutils';
 
 import { CommandRegistry } from '@phosphor/commands';
 
@@ -53,7 +53,6 @@ const plugin: JupyterLabPlugin<void> = {
 
     try {
       const settings = await registry.load(plugin.id);
-
       Private.loadShortcuts(commands, settings.composite);
       settings.changed.connect(() => {
         Private.loadShortcuts(commands, settings.composite);
@@ -130,6 +129,16 @@ namespace Private {
     // Transform the settings object to return different annotated defaults
     // calculated from all the keyboard shortcuts in the registry instead of
     // using the default values from this plugin's schema.
-    return settings => settings;
+    class ShortcutSettings extends Settings {
+      annotatedDefaults(): string {
+        return 'These are the annotated defaults.';
+      }
+    }
+
+    return settings => {
+      const plugin = registry.plugins.filter(p => p.id === settings.plugin)[0];
+
+      return new ShortcutSettings({ plugin, registry });
+    };
   }
 }