diff --git a/IPython/html/static/notebook/js/keyboardmanager.js b/IPython/html/static/notebook/js/keyboardmanager.js
index 4b8910f04..0b32f4483 100644
--- a/IPython/html/static/notebook/js/keyboardmanager.js
+++ b/IPython/html/static/notebook/js/keyboardmanager.js
@@ -167,7 +167,7 @@ var IPython = (function (IPython) {
event.preventDefault();
IPython.notebook.command_mode();
IPython.notebook.select_prev();
- IPython.notebook.edit_mode();
+ IPython.notebook.trigger_edit_mode();
return false;
}
}
@@ -181,7 +181,7 @@ var IPython = (function (IPython) {
event.preventDefault();
IPython.notebook.command_mode();
IPython.notebook.select_next();
- IPython.notebook.edit_mode();
+ IPython.notebook.trigger_edit_mode();
return false;
}
}
@@ -253,7 +253,7 @@ var IPython = (function (IPython) {
help : 'edit mode',
help_index : 'aa',
handler : function (event) {
- IPython.notebook.edit_mode();
+ IPython.notebook.trigger_edit_mode();
return false;
}
},
diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js
index 729e59756..42f5fcc4e 100644
--- a/IPython/html/static/notebook/js/notebook.js
+++ b/IPython/html/static/notebook/js/notebook.js
@@ -116,7 +116,7 @@ var IPython = (function (IPython) {
});
$([IPython.events]).on('edit_mode.Cell', function (event, data) {
- that.edit_mode(that.find_cell_index(data.cell), false);
+ that.handle_edit_mode(that.find_cell_index(data.cell));
});
$([IPython.events]).on('command_mode.Cell', function (event, data) {
@@ -540,37 +540,47 @@ var IPython = (function (IPython) {
};
/**
- * Make the notebook enter edit mode.
+ * Handle when a cell fires it's edit_mode event.
*
- * @method edit_mode
+ * @method handle_edit_mode
* @param [index] {int} Cell index to select. If no index is provided,
* the current selected cell is used.
- * @param [focust_editor] {bool} Should this method focus the cell's editor? Defaults to true.
**/
- Notebook.prototype.edit_mode = function (index, focus_editor) {
- if (focus_editor===undefined) {
- focus_editor = true;
- }
- // Must explictly check for undefined CBool(0) = false.
- if (index===undefined) {
- index = this.get_selected_index();
- } else {
- this.select(index);
- }
+ Notebook.prototype.handle_edit_mode = function (index) {
// Make sure the cell exists.
var cell = this.get_cell(index);
if (cell === null) { return; }
// Set the cell to edit mode and notify the keyboard manager if this
// is a change of mode for the notebook as a whole.
- cell.edit_mode(focus_editor);
if (this.mode !== 'edit') {
+ cell.edit_mode(focus_editor);
this.mode = 'edit';
$([IPython.events]).trigger('edit_mode.Notebook');
IPython.keyboard_manager.edit_mode();
}
};
+ /**
+ * Make a cell enter edit mode.
+ *
+ * @method trigger_edit_mode
+ * @param [index] {int} Cell index to select. If no index is provided,
+ * the current selected cell is used.
+ **/
+ Notebook.prototype.trigger_edit_mode = function (index) {
+ if (index===undefined) {
+ index = this.get_selected_index();
+ }
+ // Make sure the cell exists.
+ var cell = this.get_cell(index);
+ if (cell === null) { return; }
+ if (cell.mode != 'edit') {
+ cell.unrender();
+ cell.focus_editor();
+ }
+ };
+
/**
* Focus the currently selected cell.
*
@@ -1458,14 +1468,14 @@ var IPython = (function (IPython) {
// If we are at the end always insert a new cell and return
if (cell_index === (this.ncells()-1)) {
this.insert_cell_below('code');
- this.edit_mode(cell_index+1, true);
+ this.trigger_edit_mode(cell_index+1);
this.scroll_to_bottom();
this.set_dirty(true);
return;
}
this.insert_cell_below('code');
- this.edit_mode(cell_index+1, true);
+ this.trigger_edit_mode(cell_index+1);
this.set_dirty(true);
};
@@ -1484,7 +1494,7 @@ var IPython = (function (IPython) {
// If we are at the end always insert a new cell and return
if (cell_index === (this.ncells()-1)) {
this.insert_cell_below('code');
- this.edit_mode(cell_index+1, true);
+ this.trigger_edit_mode(cell_index+1);
this.scroll_to_bottom();
this.set_dirty(true);
return;
@@ -1960,7 +1970,7 @@ var IPython = (function (IPython) {
console.log('load notebook success');
if (this.ncells() === 0) {
this.insert_cell_below('code');
- this.edit_mode(0, true);
+ this.trigger_edit_mode(0);
} else {
this.select(0);
this.command_mode();
diff --git a/IPython/html/static/notebook/js/textcell.js b/IPython/html/static/notebook/js/textcell.js
index fbffe8c13..c70888385 100644
--- a/IPython/html/static/notebook/js/textcell.js
+++ b/IPython/html/static/notebook/js/textcell.js
@@ -105,7 +105,10 @@ var IPython = (function (IPython) {
if (that.selected === false) {
$([IPython.events]).trigger('select.Cell', {'cell':that});
}
- $([IPython.events]).trigger('edit_mode.Cell', {cell: that});
+ var cont = that.unrender();
+ if (cont) {
+ that.focus_editor();
+ }
});
};