Ver Fonte

More cleanup

Steven Silvester há 8 anos atrás
pai
commit
3e1256bc40

+ 3 - 10
src/common/observablevector.ts

@@ -432,16 +432,9 @@ class ObservableVector<T> extends Vector<T> implements IObservableVector<T> {
    * Comparison is performed using strict `===` equality.
    */
   remove(value: T): number {
-    let oldIndex = indexOf(this, value);
-    let num = super.remove(value);
-    this.changed.emit({
-      type: 'remove',
-      oldIndex,
-      newIndex: -1,
-      oldValues: new Vector([value]),
-      newValues: this._emptySequence
-    });
-    return num;
+    let index = indexOf(this, value);
+    this.removeAt(index);
+    return index;
   }
 
   /**

+ 14 - 13
src/notebook/common/undo.ts

@@ -103,6 +103,13 @@ class ObservableUndoableVector<T extends ISerializable> extends ObservableVector
     return this._index >= 0;
   }
 
+  /**
+   * Test whether the vector is disposed.
+   */
+  get isDisposed(): boolean {
+    return this._factory === null;
+  }
+
   /**
    * Dispose of the resources held by the model.
    */
@@ -183,7 +190,7 @@ class ObservableUndoableVector<T extends ISerializable> extends ObservableVector
    * Handle a change in the vector.
    */
   private _onVectorChanged(list: IObservableVector<T>, change: ObservableVector.IChangedArgs<T>): void {
-    if (!this._isUndoable) {
+    if (this.isDisposed || !this._isUndoable) {
       return;
     }
     // Clear everything after this position if necessary.
@@ -211,6 +218,7 @@ class ObservableUndoableVector<T extends ISerializable> extends ObservableVector
    */
   private _undoChange(change: ObservableVector.IChangedArgs<JSONObject>): void {
     let index = 0;
+    let factory = this._factory;
     switch (change.type) {
     case 'add':
       each(change.newValues, () => {
@@ -220,13 +228,13 @@ class ObservableUndoableVector<T extends ISerializable> extends ObservableVector
     case 'set':
       index = change.oldIndex;
       each(change.oldValues, value => {
-        this.set(index++, this._createValue(value));
+        this.set(index++, factory(value));
       });
       break;
     case 'remove':
       index = change.oldIndex;
       each(change.oldValues, value => {
-        this.insert(index++, this._createValue(value));
+        this.insert(index++, factory(value));
       });
       break;
     case 'move':
@@ -242,17 +250,18 @@ class ObservableUndoableVector<T extends ISerializable> extends ObservableVector
    */
   private _redoChange(change: ObservableVector.IChangedArgs<JSONObject>): void {
     let index = 0;
+    let factory = this._factory;
     switch (change.type) {
     case 'add':
       index = change.newIndex;
       each(change.newValues, value => {
-        this.insert(index++, this._createValue(value));
+        this.insert(index++, factory(value));
       });
       break;
     case 'set':
       index = change.newIndex;
       each(change.newValues, value => {
-        this.set(change.newIndex++, this._createValue(value));
+        this.set(change.newIndex++, factory(value));
       });
       break;
     case 'remove':
@@ -268,14 +277,6 @@ class ObservableUndoableVector<T extends ISerializable> extends ObservableVector
     }
   }
 
-  /**
-   * Create a value from JSON.
-   */
-  private _createValue(data: JSONObject): T {
-    let factory = this._factory;
-    return factory(data);
-  }
-
   /**
    * Copy a change as JSON.
    */

+ 2 - 1
src/notebook/notebook/widget.ts

@@ -359,7 +359,8 @@ class StaticNotebook extends Widget {
       index = args.newIndex;
       each(args.newValues, value => {
         this._removeCell(index);
-        this._insertCell(index++, value);
+        this._insertCell(index, value);
+        index++;
       });
       break;
     default: