From 86a628ede988fe7e54f25d1803fe913cadf325ec 2014-02-28 22:18:56 From: Jonathan Frederic Date: 2014-02-28 22:18:56 Subject: [PATCH] implemented whiteboard logic --- diff --git a/IPython/html/static/notebook/js/keyboardmanager.js b/IPython/html/static/notebook/js/keyboardmanager.js index 4b8910f..0b32f44 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 729e597..42f5fcc 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,31 +540,21 @@ 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(); @@ -572,6 +562,26 @@ var IPython = (function (IPython) { }; /** + * 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. * * @method focus_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 fbffe8c..c708883 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(); + } }); };