diff --git a/IPython/html/static/notebook/js/actions.js b/IPython/html/static/notebook/js/actions.js index be3d768..5848be5 100644 --- a/IPython/html/static/notebook/js/actions.js +++ b/IPython/html/static/notebook/js/actions.js @@ -368,14 +368,24 @@ define(function(require){ return env.notebook.scroll_manager.scroll(-1); }, }, - 'recenter-top-bottom': { - help: "Move the current cell to the center, top or bottom", + 'recenter': { + help: "Move the current cell to the center", handler: function (env, event) { if(event){ event.preventDefault(); } var cell = env.notebook.get_selected_index(); - return env.notebook.scroll_to_cell(cell); + return env.notebook.scroll_middle_to_cell(cell, 0); + } + }, + 'top': { + help: "Move the current cell to the top", + handler: function (env, event) { + if(event){ + event.preventDefault(); + } + var cell = env.notebook.get_selected_index(); + return env.notebook.scroll_to_cell(cell, 0); } }, 'save-notebook':{ diff --git a/IPython/html/static/notebook/js/keyboardmanager.js b/IPython/html/static/notebook/js/keyboardmanager.js index 3e41fa7..c29fc3f 100644 --- a/IPython/html/static/notebook/js/keyboardmanager.js +++ b/IPython/html/static/notebook/js/keyboardmanager.js @@ -80,7 +80,8 @@ define([ 'down' : 'ipython.move-cursor-down-or-next-cell', 'ctrl-shift--' : 'ipython.split-cell-at-cursor', 'ctrl-shift-subtract' : 'ipython.split-cell-at-cursor', - 'ctrl-l' : 'ipython.recenter-top-bottom' + 'ctrl-l' : 'ipython.recenter', + 'ctrl-shift-l' : 'ipython.top' }; }; diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index bc33c98..37e4361 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -361,6 +361,29 @@ define(function (require) { }; /** + * Scroll the middle of the page to a given cell. + * + * @param {integer} index - An index of the cell to view + * @param {integer} time - Animation time in milliseconds + * @return {integer} Pixel offset from the top of the container + */ + Notebook.prototype.scroll_middle_to_cell = function (index, time) { + var cells = this.get_cells(); + time = time || 0; + index = Math.min(cells.length-1,index); + index = Math.max(0 ,index); + // var scroll_value = cells[index].element.position().top-cells[0].element.position().top ; + var sme = this.scroll_manager.element; + var h = sme.height(); + var st = sme.scrollTop(); + var t = sme.offset().top; + var ct = cells[index].element.offset().top; + var scroll_value = st + ct - (t + h/2); + this.scroll_manager.element.animate({scrollTop:scroll_value}, time); + return scroll_value; + }; + + /** * Scroll to the bottom of the page. */ Notebook.prototype.scroll_to_bottom = function () {