浏览代码

Fix implementation of `set` operation.

Ian Rose 8 年之前
父节点
当前提交
7aa982da9a
共有 1 个文件被更改,包括 6 次插入3 次删除
  1. 6 3
      packages/notebook/src/widget.ts

+ 6 - 3
packages/notebook/src/widget.ts

@@ -356,8 +356,11 @@ class StaticNotebook extends Widget {
       // TODO: reuse existing widgets if possible.
       index = args.newIndex;
       each(args.newValues, value => {
-        this._removeCell(index);
+        // Note: this ordering (insert then remove)
+        // is important for getting the active cell
+        // index for the editable notebook correct.
         this._insertCell(index, value);
+        this._removeCell(index+1);
         index++;
       });
       break;
@@ -1001,10 +1004,10 @@ class Notebook extends StaticNotebook {
   /**
    * Handle a cell being removed.
    */
-  protected onCellRemoved(index:number, cell: BaseCellWidget): void {
+  protected onCellRemoved(index: number, cell: BaseCellWidget): void {
     // If the removal happened above, decrement the active
     // cell index, otherwise it stays the same.
-    this.activeCellIndex = index < this.activeCellIndex ?
+    this.activeCellIndex = index <= this.activeCellIndex ?
       this.activeCellIndex - 1 : this.activeCellIndex ;
     if (this.isSelected(cell)) {
       this._selectionChanged.emit(void 0);