diff --git a/IPython/html/static/notebook/js/actions.js b/IPython/html/static/notebook/js/actions.js
index d3f194e9f..245f4ecb7 100644
--- a/IPython/html/static/notebook/js/actions.js
+++ b/IPython/html/static/notebook/js/actions.js
@@ -368,6 +368,26 @@ define(function(require){
return env.notebook.scroll_manager.scroll(-1);
},
},
+ 'scroll-cell-center': {
+ help: "Scroll 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_cell_percent(cell, 50, 0);
+ }
+ },
+ 'scroll-cell-top': {
+ help: "Scroll 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_cell_percent(cell, 0, 0);
+ }
+ },
'save-notebook':{
help: "Save and Checkpoint",
help_index : 'fb',
diff --git a/IPython/html/static/notebook/js/keyboardmanager.js b/IPython/html/static/notebook/js/keyboardmanager.js
index 82d3d36e2..e1a3eab13 100644
--- a/IPython/html/static/notebook/js/keyboardmanager.js
+++ b/IPython/html/static/notebook/js/keyboardmanager.js
@@ -79,7 +79,7 @@ define([
'up' : 'ipython.move-cursor-up-or-previous-cell',
'down' : 'ipython.move-cursor-down-or-next-cell',
'ctrl-shift--' : 'ipython.split-cell-at-cursor',
- 'ctrl-shift-subtract' : 'ipython.split-cell-at-cursor'
+ 'ctrl-shift-subtract' : 'ipython.split-cell-at-cursor',
};
};
diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js
index bc33c9817..19ae22778 100644
--- a/IPython/html/static/notebook/js/notebook.js
+++ b/IPython/html/static/notebook/js/notebook.js
@@ -351,11 +351,30 @@ define(function (require) {
* @return {integer} Pixel offset from the top of the container
*/
Notebook.prototype.scroll_to_cell = function (index, time) {
+ return this.scroll_cell_percent(index, 0, time);
+ };
+
+ /**
+ * Scroll the middle of the page to a given cell.
+ *
+ * @param {integer} index - An index of the cell to view
+ * @param {integer} percent - 0-100, the location on the screen to scroll.
+ * 0 is the top, 100 is the bottom.
+ * @param {integer} time - Animation time in milliseconds
+ * @return {integer} Pixel offset from the top of the container
+ */
+ Notebook.prototype.scroll_cell_percent = function (index, percent, time) {
var cells = this.get_cells();
time = time || 0;
+ percent = percent || 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 + .01 * percent * h);
this.scroll_manager.element.animate({scrollTop:scroll_value}, time);
return scroll_value;
};