Parcourir la source

Fix typing errors caught in ts 3.5

Jason Grout il y a 6 ans
Parent
commit
79933e720a

+ 14 - 22
packages/fileeditor-extension/src/index.ts

@@ -145,14 +145,10 @@ export const tabSpaceStatus: JupyterFrontEndPlugin<void> = {
 
     // Keep a reference to the code editor config from the settings system.
     const updateSettings = (settings: ISettingRegistry.ISettings): void => {
-      const cached = settings.get('editorConfig').composite as Partial<
-        CodeEditor.IConfig
-      >;
-      const config: CodeEditor.IConfig = {
+      item.model!.config = {
         ...CodeEditor.defaultConfig,
-        ...cached
+        ...(settings.get('editorConfig').composite as JSONObject)
       };
-      item.model!.config = config;
     };
     void Promise.all([
       settingRegistry.load('@jupyterlab/fileeditor-extension:plugin'),
@@ -215,7 +211,7 @@ function activate(
     tracker.currentWidget !== null &&
     tracker.currentWidget === shell.currentWidget;
 
-  let config = { ...CodeEditor.defaultConfig };
+  let config: CodeEditor.IConfig = { ...CodeEditor.defaultConfig };
 
   // Handle state restoration.
   if (restorer) {
@@ -230,15 +226,11 @@ function activate(
    * Update the setting values.
    */
   function updateSettings(settings: ISettingRegistry.ISettings): void {
-    let cached = settings.get('editorConfig').composite as Partial<
-      CodeEditor.IConfig
-    >;
-    Object.keys(config).forEach((key: keyof CodeEditor.IConfig) => {
-      config[key] =
-        cached[key] === null || cached[key] === undefined
-          ? CodeEditor.defaultConfig[key]
-          : cached[key];
-    });
+    config = {
+      ...CodeEditor.defaultConfig,
+      ...(settings.get('editorConfig').composite as JSONObject)
+    };
+
     // Trigger a refresh of the rendered commands
     app.commands.notifyCommandChanged();
   }
@@ -313,7 +305,7 @@ function activate(
       const currentSize = config.fontSize || cssSize;
       config.fontSize = currentSize + delta;
       return settingRegistry
-        .set(id, 'editorConfig', config)
+        .set(id, 'editorConfig', (config as unknown) as JSONObject)
         .catch((reason: Error) => {
           console.error(`Failed to set ${id}: ${reason.message}`);
         });
@@ -325,7 +317,7 @@ function activate(
     execute: () => {
       config.lineNumbers = !config.lineNumbers;
       return settingRegistry
-        .set(id, 'editorConfig', config)
+        .set(id, 'editorConfig', (config as unknown) as JSONObject)
         .catch((reason: Error) => {
           console.error(`Failed to set ${id}: ${reason.message}`);
         });
@@ -342,7 +334,7 @@ function activate(
       const lineWrap = (args['mode'] as wrappingMode) || 'off';
       config.lineWrap = lineWrap;
       return settingRegistry
-        .set(id, 'editorConfig', config)
+        .set(id, 'editorConfig', (config as unknown) as JSONObject)
         .catch((reason: Error) => {
           console.error(`Failed to set ${id}: ${reason.message}`);
         });
@@ -361,7 +353,7 @@ function activate(
       config.tabSize = (args['size'] as number) || 4;
       config.insertSpaces = !!args['insertSpaces'];
       return settingRegistry
-        .set(id, 'editorConfig', config)
+        .set(id, 'editorConfig', (config as unknown) as JSONObject)
         .catch((reason: Error) => {
           console.error(`Failed to set ${id}: ${reason.message}`);
         });
@@ -377,7 +369,7 @@ function activate(
     execute: () => {
       config.matchBrackets = !config.matchBrackets;
       return settingRegistry
-        .set(id, 'editorConfig', config)
+        .set(id, 'editorConfig', (config as unknown) as JSONObject)
         .catch((reason: Error) => {
           console.error(`Failed to set ${id}: ${reason.message}`);
         });
@@ -391,7 +383,7 @@ function activate(
     execute: () => {
       config.autoClosingBrackets = !config.autoClosingBrackets;
       return settingRegistry
-        .set(id, 'editorConfig', config)
+        .set(id, 'editorConfig', (config as unknown) as JSONObject)
         .catch((reason: Error) => {
           console.error(`Failed to set ${id}: ${reason.message}`);
         });

+ 17 - 32
packages/notebook-extension/src/index.ts

@@ -18,7 +18,7 @@ import {
 
 import { CodeCell } from '@jupyterlab/cells';
 
-import { CodeEditor, IEditorServices } from '@jupyterlab/codeeditor';
+import { IEditorServices } from '@jupyterlab/codeeditor';
 
 import {
   ISettingRegistry,
@@ -31,7 +31,7 @@ import { IDocumentManager } from '@jupyterlab/docmanager';
 
 import { ArrayExt } from '@phosphor/algorithm';
 
-import { UUID } from '@phosphor/coreutils';
+import { UUID, JSONObject } from '@phosphor/coreutils';
 
 import { DisposableSet } from '@phosphor/disposable';
 
@@ -594,36 +594,21 @@ function activateNotebookHandler(
    * Update the setting values.
    */
   function updateConfig(settings: ISettingRegistry.ISettings): void {
-    let cached = settings.get('codeCellConfig').composite as Partial<
-      CodeEditor.IConfig
-    >;
-    let code = { ...StaticNotebook.defaultEditorConfig.code };
-    Object.keys(code).forEach((key: keyof CodeEditor.IConfig) => {
-      code[key] =
-        cached[key] === null || cached[key] === undefined
-          ? code[key]
-          : cached[key];
-    });
-    cached = settings.get('markdownCellConfig').composite as Partial<
-      CodeEditor.IConfig
-    >;
-    let markdown = { ...StaticNotebook.defaultEditorConfig.markdown };
-    Object.keys(markdown).forEach((key: keyof CodeEditor.IConfig) => {
-      markdown[key] =
-        cached[key] === null || cached[key] === undefined
-          ? markdown[key]
-          : cached[key];
-    });
-    cached = settings.get('rawCellConfig').composite as Partial<
-      CodeEditor.IConfig
-    >;
-    let raw = { ...StaticNotebook.defaultEditorConfig.raw };
-    Object.keys(raw).forEach((key: keyof CodeEditor.IConfig) => {
-      raw[key] =
-        cached[key] === null || cached[key] === undefined
-          ? raw[key]
-          : cached[key];
-    });
+    let code = {
+      ...StaticNotebook.defaultEditorConfig.code,
+      ...(settings.get('codeCellConfig').composite as JSONObject)
+    };
+
+    let markdown = {
+      ...StaticNotebook.defaultEditorConfig.markdown,
+      ...(settings.get('markdownCellConfig').composite as JSONObject)
+    };
+
+    let raw = {
+      ...StaticNotebook.defaultEditorConfig.raw,
+      ...(settings.get('rawCellConfig').composite as JSONObject)
+    };
+
     factory.editorConfig = { code, markdown, raw };
     factory.notebookConfig = {
       scrollPastEnd: settings.get('scrollPastEnd').composite as boolean,

+ 7 - 9
packages/terminal-extension/src/index.ts

@@ -108,17 +108,14 @@ function activate(
     });
   }
 
-  // The terminal options from the setting editor.
+  // The cached terminal options from the setting editor.
   let options: Partial<ITerminal.IOptions>;
 
   /**
-   * Update the option values.
+   * Update the cached option values.
    */
   function updateOptions(settings: ISettingRegistry.ISettings): void {
-    options = settings.composite as Partial<ITerminal.IOptions>;
-    Object.keys(options).forEach((key: keyof ITerminal.IOptions) => {
-      ITerminal.defaultOptions[key] = options[key];
-    });
+    options = settings.composite;
   }
 
   /**
@@ -164,7 +161,7 @@ function activate(
     });
   });
 
-  addCommands(app, tracker, settingRegistry);
+  addCommands(app, tracker, settingRegistry, options);
 
   if (mainMenu) {
     // Add "Terminal Theme" menu below "JupyterLab Themes" menu.
@@ -248,7 +245,8 @@ function activate(
 export function addCommands(
   app: JupyterFrontEnd,
   tracker: InstanceTracker<MainAreaWidget<ITerminal.ITerminal>>,
-  settingRegistry: ISettingRegistry
+  settingRegistry: ISettingRegistry,
+  options: Partial<ITerminal.IOptions>
 ) {
   const { commands, serviceManager } = app;
 
@@ -274,7 +272,7 @@ export function addCommands(
             .catch(() => serviceManager.terminals.startNew())
         : serviceManager.terminals.startNew());
 
-      const term = new Terminal(session);
+      const term = new Terminal(session, options);
 
       term.title.icon = TERMINAL_ICON_CLASS;
       term.title.label = '...';