Ongoing work on cell splitting.

This commit is contained in:
Brian E. Granger 2014-01-08 10:11:23 -08:00
parent 177fb9bb5d
commit b3322fc2d5
3 changed files with 23 additions and 27 deletions

View File

@ -167,6 +167,13 @@ var IPython = (function (IPython) {
};
}
},
'alt+-' : {
help : 'split cell',
handler : function (event) {
IPython.notebook.split_cell();
return false;
}
},
}
// Command mode defaults

View File

@ -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();
}
};
};

View File

@ -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}