From ac6d1bb1016b5ddf482036dbd5001de87a653f53 2012-01-18 02:27:58
From: Brian Granger <ellisonbg@gmail.com>
Date: 2012-01-18 02:27:58
Subject: [PATCH] More of the initial split cell capability.

---

diff --git a/IPython/frontend/html/notebook/static/js/notebook.js b/IPython/frontend/html/notebook/static/js/notebook.js
index 6324f17..91311af 100644
--- a/IPython/frontend/html/notebook/static/js/notebook.js
+++ b/IPython/frontend/html/notebook/static/js/notebook.js
@@ -578,7 +578,7 @@ var IPython = (function (IPython) {
     };
 
 
-    // Copy/Paste
+    // Copy/Paste/Merge/Split
 
     Notebook.prototype.enable_paste = function () {
         var that = this;
@@ -663,6 +663,23 @@ var IPython = (function (IPython) {
     };
 
 
+    Notebook.prototype.split_cell = function () {
+        var cell = this.selected_cell();
+        if (cell instanceof IPython.CodeCell) {
+            var cursor = cell.code_mirror.getCursor();
+            var last_line_num = cell.code_mirror.lineCount()-1;
+            var last_line_len = cell.code_mirror.getLine(last_line_num).length;
+            var end = {line:last_line_num, ch:last_line_len}
+            var texta = cell.code_mirror.getRange({line:0,ch:0}, cursor);
+            var textb = cell.code_mirror.getRange(cursor, end);
+            texta = texta.replace(/^\n+/, '').replace(/\n+$/, '');
+            textb = textb.replace(/^\n+/, '').replace(/\n+$/, '');
+            cell.set_code(texta);
+            var new_cell = this.insert_code_cell_below();
+            new_cell.set_code(textb);
+        };
+    };
+
     // Cell collapsing and output clearing
 
     Notebook.prototype.collapse = function (index) {