Merge pull request #8281 from minrk/finish-8067

finish scroll-cell PR
Min RK 11 years ago
commit 3728a48420

@ -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',

@ -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',
};
};

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

Loading…
Cancel
Save