Browse Source

wip move cells up/down

Steven Silvester 8 years ago
parent
commit
7f82503b6b
1 changed files with 46 additions and 0 deletions
  1. 46 0
      src/notebook/notebook/actions.ts

+ 46 - 0
src/notebook/notebook/actions.ts

@@ -248,6 +248,52 @@ namespace NotebookActions {
     Private.deselectCells(widget);
   }
 
+  /**
+   * Move the selected cell(s) down.
+   *
+   * @param widget = The target notebook widget.
+   */
+  export
+  function moveDown(widget: Notebook): void {
+    if (!widget.model || !widget.activeCell) {
+      return;
+    }
+    let cells = widget.model.cells;
+    cells.beginCompoundOperation();
+    for (let i = cells.length - 2; i > 0; i--) {
+      if (widget.isSelected(widget.childAt(i))) {
+        if (!widget.isSelected(widget.childAt(i + 1))) {
+          cells.move(i, i + 1);
+          widget.select(widget.childAt(i + 1));
+        }
+      }
+    }
+    cells.endCompoundOperation();
+  }
+
+  /**
+   * Move the selected cell(s) up.
+   *
+   * @param widget - The target notebook widget.
+   */
+  export
+  function moveUp(widget: Notebook): void {
+    if (!widget.model || !widget.activeCell) {
+      return;
+    }
+    let cells = widget.model.cells;
+    cells.beginCompoundOperation();
+    for (let i = 1; i < cells.length; i++) {
+      if (widget.isSelected(widget.childAt(i))) {
+        if (!widget.isSelected(widget.childAt(i - 1))) {
+          cells.move(i, i - 1);
+          widget.select(widget.childAt(i - 1));
+        }
+      }
+    }
+    cells.endCompoundOperation();
+  }
+
   /**
    * Change the selected cell type(s).
    *