Bläddra i källkod

Fixed cell manager when debugger panel is closed and reopened

Johan Mabille 5 år sedan
förälder
incheckning
d81da30a1b
3 ändrade filer med 39 tillägg och 17 borttagningar
  1. 28 17
      src/handlers/cell.ts
  2. 6 0
      src/service.ts
  3. 5 0
      src/tokens.ts

+ 28 - 17
src/handlers/cell.ts

@@ -21,31 +21,42 @@ const LINE_HIGHLIGHT_CLASS = 'jp-breakpoint-line-highlight';
 
 export class CellManager implements IDisposable {
   constructor(options: CellManager.IOptions) {
-    this._debuggerModel = options.debuggerModel;
     this._debuggerService = options.debuggerService;
-    this.breakpointsModel = options.breakpointsModel;
+    this.onModelChanged();
+    this._debuggerService.modelChanged.connect(() => this.onModelChanged());
     this.activeCell = options.activeCell;
     this.onActiveCellChanged();
+  }
 
-    this._debuggerModel.variablesModel.changed.connect(() => {
-      this.cleanupHighlight();
-      const firstFrame = this._debuggerModel.callstackModel.frames[0];
-      if (!firstFrame) {
-        return;
-      }
-      this.showCurrentLine(firstFrame.line);
-    });
+  isDisposed: boolean;
+
+  private onModelChanged() {
+    this._debuggerModel = this._debuggerService.model;
+    if (this._debuggerModel) {
+      this.breakpointsModel = this._debuggerModel.breakpointsModel;
+
+      this._debuggerModel.variablesModel.changed.connect(() => {
+        this.cleanupHighlight();
+        const firstFrame = this._debuggerModel.callstackModel.frames[0];
+        if (!firstFrame) {
+          return;
+        }
+        this.showCurrentLine(firstFrame.line);
+      });
 
-    this.breakpointsModel.changed.connect(async () => {
-      if (!this.activeCell || this.activeCell.isDisposed) {
-        return;
+      this.breakpointsModel.changed.connect(async () => {
+        if (!this.activeCell || this.activeCell.isDisposed) {
+          return;
+        }
+        this.addBreakpointsToEditor(this.activeCell);
+      });
+
+      if (this.activeCell) {
+        this._debuggerModel.codeValue = this.activeCell.model.value;
       }
-      this.addBreakpointsToEditor(this.activeCell);
-    });
+    }
   }
 
-  isDisposed: boolean;
-
   private showCurrentLine(lineNumber: number) {
     if (!this.activeCell) {
       return;

+ 6 - 0
src/service.ts

@@ -56,6 +56,7 @@ export class DebugService implements IDebugger {
 
   set model(model: Debugger.Model) {
     this._model = model;
+    this._modelChanged.emit(model);
   }
 
   get session(): IDebugger.ISession {
@@ -154,6 +155,10 @@ export class DebugService implements IDebugger {
     return this._sessionChanged;
   }
 
+  get modelChanged(): ISignal<IDebugger, Debugger.Model> {
+    return this._modelChanged;
+  }
+
   get eventMessage(): ISignal<IDebugger, IDebugger.ISession.Event> {
     return this._eventMessage;
   }
@@ -299,6 +304,7 @@ export class DebugService implements IDebugger {
   private _isDisposed: boolean = false;
   private _session: IDebugger.ISession;
   private _sessionChanged = new Signal<IDebugger, IDebugger.ISession>(this);
+  private _modelChanged = new Signal<IDebugger, Debugger.Model>(this);
   private _eventMessage = new Signal<IDebugger, IDebugger.ISession.Event>(this);
   private _model: Debugger.Model;
 

+ 5 - 0
src/tokens.ts

@@ -100,6 +100,11 @@ export interface IDebugger {
    */
   sessionChanged: ISignal<IDebugger, IDebugger.ISession>;
 
+  /**
+   * Signal emitted upon model changed.
+   */
+  modelChanged: ISignal<IDebugger, Debugger.Model>;
+
   /**
    * Signal emitted for debug event messages.
    */