##// END OF EJS Templates
Separated recenter and top actions.
Alexander Belopolsky -
Show More
@@ -368,14 +368,24 define(function(require){
368 return env.notebook.scroll_manager.scroll(-1);
368 return env.notebook.scroll_manager.scroll(-1);
369 },
369 },
370 },
370 },
371 'recenter-top-bottom': {
371 'recenter': {
372 help: "Move the current cell to the center, top or bottom",
372 help: "Move the current cell to the center",
373 handler: function (env, event) {
373 handler: function (env, event) {
374 if(event){
374 if(event){
375 event.preventDefault();
375 event.preventDefault();
376 }
376 }
377 var cell = env.notebook.get_selected_index();
377 var cell = env.notebook.get_selected_index();
378 return env.notebook.scroll_to_cell(cell);
378 return env.notebook.scroll_middle_to_cell(cell, 0);
379 }
380 },
381 'top': {
382 help: "Move the current cell to the top",
383 handler: function (env, event) {
384 if(event){
385 event.preventDefault();
386 }
387 var cell = env.notebook.get_selected_index();
388 return env.notebook.scroll_to_cell(cell, 0);
379 }
389 }
380 },
390 },
381 'save-notebook':{
391 'save-notebook':{
@@ -80,7 +80,8 define([
80 'down' : 'ipython.move-cursor-down-or-next-cell',
80 'down' : 'ipython.move-cursor-down-or-next-cell',
81 'ctrl-shift--' : 'ipython.split-cell-at-cursor',
81 'ctrl-shift--' : 'ipython.split-cell-at-cursor',
82 'ctrl-shift-subtract' : 'ipython.split-cell-at-cursor',
82 'ctrl-shift-subtract' : 'ipython.split-cell-at-cursor',
83 'ctrl-l' : 'ipython.recenter-top-bottom'
83 'ctrl-l' : 'ipython.recenter',
84 'ctrl-shift-l' : 'ipython.top'
84 };
85 };
85 };
86 };
86
87
@@ -361,6 +361,29 define(function (require) {
361 };
361 };
362
362
363 /**
363 /**
364 * Scroll the middle of the page to a given cell.
365 *
366 * @param {integer} index - An index of the cell to view
367 * @param {integer} time - Animation time in milliseconds
368 * @return {integer} Pixel offset from the top of the container
369 */
370 Notebook.prototype.scroll_middle_to_cell = function (index, time) {
371 var cells = this.get_cells();
372 time = time || 0;
373 index = Math.min(cells.length-1,index);
374 index = Math.max(0 ,index);
375 // var scroll_value = cells[index].element.position().top-cells[0].element.position().top ;
376 var sme = this.scroll_manager.element;
377 var h = sme.height();
378 var st = sme.scrollTop();
379 var t = sme.offset().top;
380 var ct = cells[index].element.offset().top;
381 var scroll_value = st + ct - (t + h/2);
382 this.scroll_manager.element.animate({scrollTop:scroll_value}, time);
383 return scroll_value;
384 };
385
386 /**
364 * Scroll to the bottom of the page.
387 * Scroll to the bottom of the page.
365 */
388 */
366 Notebook.prototype.scroll_to_bottom = function () {
389 Notebook.prototype.scroll_to_bottom = function () {
General Comments 0
You need to be logged in to leave comments. Login now