From bdb4c53f2bdf1e79f62741fab174a99fc1a19d53 2014-01-08 18:11:23 From: Brian E. Granger Date: 2014-01-08 18:11:23 Subject: [PATCH] Ongoing work on cell splitting. --- diff --git a/IPython/html/static/notebook/js/keyboardmanager.js b/IPython/html/static/notebook/js/keyboardmanager.js index cbb859a..6b46e9d 100644 --- a/IPython/html/static/notebook/js/keyboardmanager.js +++ b/IPython/html/static/notebook/js/keyboardmanager.js @@ -167,6 +167,13 @@ var IPython = (function (IPython) { }; } }, + 'alt+-' : { + help : 'split cell', + handler : function (event) { + IPython.notebook.split_cell(); + return false; + } + }, } // Command mode defaults diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index 38b5d0a..65df08c 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -1053,27 +1053,31 @@ var IPython = (function (IPython) { if (cell.is_splittable()) { var texta = cell.get_pre_cursor(); var textb = cell.get_post_cursor(); + var mode = cell.mode; if (cell instanceof IPython.CodeCell) { + // In this case the operations keep the notebook in its existing mode + // so we don't need to do any post-op mode changes. cell.set_text(textb); var new_cell = this.insert_cell_above('code'); new_cell.set_text(texta); - this.select_next(); - } else if (cell instanceof IPython.MarkdownCell) { - var render = cell.rendered; + } else if (cell instanceof IPython.MarkdownCell && !cell.rendered) { cell.set_text(textb); cell.render(); var new_cell = this.insert_cell_above('markdown'); - new_cell.unrender(); // editor must be visible to call set_text + // Editor must be visible to call set_text, so we unrender. + // Note that this call will focus the CM editor, which selects + // this cell and enters edit mode. + new_cell.unrender(); new_cell.set_text(texta); new_cell.render(); - this.select_next(); - if (!render) { - // The final rendered state of the split cells should - // match the original cell's state. The order matters - // here as we want the lower cell (cell) to be selected. - new_cell.unrender(); - cell.unrender(); - } + // The final rendered state of the split cells should + // match the original cell's state. The order matters + // here as we want the lower cell (cell) to be selected. + // Each of these involves a CM focus and cell select. + new_cell.unrender(); + cell.unrender(); + console.log('setting edit mode...') + this.edit_mode(); } }; }; diff --git a/IPython/html/static/notebook/js/textcell.js b/IPython/html/static/notebook/js/textcell.js index 45ddf19..cf0edbc 100644 --- a/IPython/html/static/notebook/js/textcell.js +++ b/IPython/html/static/notebook/js/textcell.js @@ -262,21 +262,6 @@ var IPython = (function (IPython) { }; }; - - /** @method at_bottom **/ - TextCell.prototype.at_bottom = function () { - if (this.rendered) { - return true - } else { - var cursor = this.code_mirror.getCursor(); - if (cursor.line === (this.code_mirror.lineCount()-1) && cursor.ch === this.code_mirror.getLine(cursor.line).length) { - return true; - } else { - return false; - }; - }; - }; - /** * @method at_bottom * @return {Boolean}