Afshin Darian 8 лет назад
Родитель
Сommit
af30dc32c8
3 измененных файлов с 26 добавлено и 21 удалено
  1. 8 5
      src/completer/plugin.ts
  2. 14 12
      src/inspector/plugin.ts
  3. 4 4
      src/tooltip/plugin.ts

+ 8 - 5
src/completer/plugin.ts

@@ -64,7 +64,7 @@ const service: JupyterLabPlugin<ICompletionManager> = {
           return;
         }
 
-        const handler =handlers[id];
+        const handler = handlers[id];
         if (!handler) {
           return;
         }
@@ -119,19 +119,19 @@ const consolePlugin: JupyterLabPlugin<void> = {
     // Create a handler for each console that is created.
     consoles.widgetAdded.connect((sender, panel) => {
       const anchor = panel.console;
-      const cell = panel.console.prompt;
+      const cell = anchor.prompt;
       const editor = cell && cell.editor;
-      const kernel = panel.console.session.kernel;
+      const kernel = anchor.session.kernel;
       const parent = panel;
       const handler = manager.register({ anchor, editor, kernel, parent });
 
       // Listen for prompt creation.
-      panel.console.promptCreated.connect((sender, cell) => {
+      anchor.promptCreated.connect((sender, cell) => {
         handler.editor = cell && cell.editor;
       });
 
       // Listen for kernel changes.
-      panel.console.session.kernelChanged.connect((sender, kernel) => {
+      anchor.session.kernelChanged.connect((sender, kernel) => {
         handler.kernel = kernel;
       });
     });
@@ -140,6 +140,9 @@ const consolePlugin: JupyterLabPlugin<void> = {
     app.commands.addCommand(CommandIDs.invokeConsole, {
       execute: () => {
         const id = consoles.currentWidget && consoles.currentWidget.id;
+        if (!id) {
+          return;
+        }
         return app.commands.execute(CommandIDs.invoke, { id });
       }
     });

+ 14 - 12
src/inspector/plugin.ts

@@ -113,9 +113,7 @@ const consolePlugin: JupyterLabPlugin<void> = {
   autoStart: true,
   activate: (app: JupyterLab, manager: IInspector, consoles: IConsoleTracker): void => {
     // Maintain association of new consoles with their respective handlers.
-    const handlers = new AttachedProperty<Widget, InspectionHandler>({
-      name: 'handler'
-    });
+    const handlers: { [id: string]: InspectionHandler } = {};
 
     // Create a handler for each console that is created.
     consoles.widgetAdded.connect((sender, parent) => {
@@ -125,7 +123,7 @@ const consolePlugin: JupyterLabPlugin<void> = {
       const handler = new InspectionHandler({ kernel, rendermime });
 
       // Associate the handler to the widget.
-      handlers.set(parent, handler);
+      handlers[parent.id] = handler;
 
       // Set the initial editor.
       let cell = parent.console.prompt;
@@ -142,7 +140,10 @@ const consolePlugin: JupyterLabPlugin<void> = {
       });
 
       // Listen for parent disposal.
-      parent.disposed.connect(() => { handler.dispose(); });
+      parent.disposed.connect(() => {
+        delete handlers[parent.id];
+        handler.dispose();
+      });
     });
 
     // Keep track of console instances and set inspector source.
@@ -151,7 +152,7 @@ const consolePlugin: JupyterLabPlugin<void> = {
       if (!widget || !consoles.has(widget)) {
         return;
       }
-      let source = handlers.get(widget);
+      let source = handlers[widget.id];
       if (source) {
         manager.source = source;
       }
@@ -168,9 +169,7 @@ const notebookPlugin: JupyterLabPlugin<void> = {
   autoStart: true,
   activate: (app: JupyterLab, manager: IInspector, notebooks: INotebookTracker): void => {
     // Maintain association of new notebooks with their respective handlers.
-    const handlers = new AttachedProperty<Widget, InspectionHandler>({
-      name: 'handler'
-    });
+    const handlers: { [id: string]: InspectionHandler } = {};
 
     // Create a handler for each notebook that is created.
     notebooks.widgetAdded.connect((sender, parent) => {
@@ -179,7 +178,7 @@ const notebookPlugin: JupyterLabPlugin<void> = {
       const handler = new InspectionHandler({ kernel, rendermime });
 
       // Associate the handler to the widget.
-      handlers.set(parent, handler);
+      handlers[parent.id] = handler;
 
       // Set the initial editor.
       let cell = parent.notebook.activeCell;
@@ -196,7 +195,10 @@ const notebookPlugin: JupyterLabPlugin<void> = {
       });
 
       // Listen for parent disposal.
-      parent.disposed.connect(() => { handler.dispose(); });
+      parent.disposed.connect(() => {
+        delete handlers[parent.id];
+        handler.dispose();
+      });
     });
 
     // Keep track of notebook instances and set inspector source.
@@ -205,7 +207,7 @@ const notebookPlugin: JupyterLabPlugin<void> = {
       if (!widget || !notebooks.has(widget)) {
         return;
       }
-      let source = handlers.get(widget);
+      let source = handlers[widget.id];
       if (source) {
         manager.source = source;
       }

+ 4 - 4
src/tooltip/plugin.ts

@@ -81,9 +81,9 @@ const consolePlugin: JupyterLabPlugin<void> = {
         }
 
         const anchor = parent.console;
-        const editor = parent.console.prompt.editor;
-        const kernel = parent.console.session.kernel;
-        const rendermime = parent.console.rendermime;
+        const editor = anchor.prompt.editor;
+        const kernel = anchor.session.kernel;
+        const rendermime = anchor.rendermime;
 
         // If all components necessary for rendering exist, create a tooltip.
         if (!!editor && !!kernel && !!rendermime) {
@@ -114,7 +114,7 @@ const notebookPlugin: JupyterLabPlugin<void> = {
         }
 
         const anchor = parent.notebook;
-        const editor = parent.notebook.activeCell.editor;
+        const editor = anchor.activeCell.editor;
         const kernel = parent.kernel;
         const rendermime = parent.rendermime;