From 8f111d0f8d98e210cd27610d20aa2057fb9eeaa1 Mon Sep 17 00:00:00 2001 From: Alexander Belopolsky Date: Mon, 16 Mar 2015 14:12:12 -0400 Subject: [PATCH 1/4] Added basic scroll to bottom binding for ctrl-l. --- IPython/html/static/notebook/js/actions.js | 9 +++++++++ IPython/html/static/notebook/js/keyboardmanager.js | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/IPython/html/static/notebook/js/actions.js b/IPython/html/static/notebook/js/actions.js index d3f194e9f..7fcd6b4b2 100644 --- a/IPython/html/static/notebook/js/actions.js +++ b/IPython/html/static/notebook/js/actions.js @@ -368,6 +368,15 @@ define(function(require){ return env.notebook.scroll_manager.scroll(-1); }, }, + 'recenter-top-bottom': { + help: "Move the current cell to the center, top or bottom", + handler: function (env, event) { + if(event){ + event.preventDefault(); + } + return env.notebook.scroll_to_bottom(); + } + }, '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..3e41fa740 100644 --- a/IPython/html/static/notebook/js/keyboardmanager.js +++ b/IPython/html/static/notebook/js/keyboardmanager.js @@ -79,7 +79,8 @@ 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', + 'ctrl-l' : 'ipython.recenter-top-bottom' }; }; From 35bce22c17a1a5768700b03f6864ec40f7faabb9 Mon Sep 17 00:00:00 2001 From: Alexander Belopolsky Date: Mon, 16 Mar 2015 14:22:04 -0400 Subject: [PATCH 2/4] Changed ctrl-l action to scroll to current cell. --- IPython/html/static/notebook/js/actions.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/IPython/html/static/notebook/js/actions.js b/IPython/html/static/notebook/js/actions.js index 7fcd6b4b2..be3d768cc 100644 --- a/IPython/html/static/notebook/js/actions.js +++ b/IPython/html/static/notebook/js/actions.js @@ -374,7 +374,8 @@ define(function(require){ if(event){ event.preventDefault(); } - return env.notebook.scroll_to_bottom(); + var cell = env.notebook.get_selected_index(); + return env.notebook.scroll_to_cell(cell); } }, 'save-notebook':{ From 6d5c0725d97eb2f3015b9c0e11017935f43fdad1 Mon Sep 17 00:00:00 2001 From: Alexander Belopolsky Date: Mon, 16 Mar 2015 20:58:24 -0400 Subject: [PATCH 3/4] Separated recenter and top actions. --- IPython/html/static/notebook/js/actions.js | 16 ++++++++++--- .../static/notebook/js/keyboardmanager.js | 3 ++- IPython/html/static/notebook/js/notebook.js | 23 +++++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/IPython/html/static/notebook/js/actions.js b/IPython/html/static/notebook/js/actions.js index be3d768cc..5848be5b7 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 3e41fa740..c29fc3f61 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 bc33c9817..37e4361ec 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -360,6 +360,29 @@ define(function (require) { return scroll_value; }; + /** + * 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. */ From 1f5f0be854064515a98e4b0a8b87ed1e683081d0 Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 8 Apr 2015 10:11:11 -0700 Subject: [PATCH 4/4] address code review - remove ctrl shortcuts for scrolling - rename scroll actions 'scroll-cell-center', 'scroll-cell-top' - rename added notebook method `scroll_cell_percent` --- IPython/html/static/notebook/js/actions.js | 12 ++++++------ .../html/static/notebook/js/keyboardmanager.js | 2 -- IPython/html/static/notebook/js/notebook.js | 16 ++++++---------- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/IPython/html/static/notebook/js/actions.js b/IPython/html/static/notebook/js/actions.js index 5848be5b7..245f4ecb7 100644 --- a/IPython/html/static/notebook/js/actions.js +++ b/IPython/html/static/notebook/js/actions.js @@ -368,24 +368,24 @@ define(function(require){ return env.notebook.scroll_manager.scroll(-1); }, }, - 'recenter': { - help: "Move the current cell to the center", + '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_middle_to_cell(cell, 0); + return env.notebook.scroll_cell_percent(cell, 50, 0); } }, - 'top': { - help: "Move the current cell to the top", + '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_to_cell(cell, 0); + return env.notebook.scroll_cell_percent(cell, 0, 0); } }, 'save-notebook':{ diff --git a/IPython/html/static/notebook/js/keyboardmanager.js b/IPython/html/static/notebook/js/keyboardmanager.js index c29fc3f61..e1a3eab13 100644 --- a/IPython/html/static/notebook/js/keyboardmanager.js +++ b/IPython/html/static/notebook/js/keyboardmanager.js @@ -80,8 +80,6 @@ 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', - 'ctrl-shift-l' : 'ipython.top' }; }; diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index 37e4361ec..19ae22778 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -351,34 +351,30 @@ define(function (require) { * @return {integer} Pixel offset from the top of the container */ Notebook.prototype.scroll_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 ; - this.scroll_manager.element.animate({scrollTop:scroll_value}, time); - return scroll_value; + 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_middle_to_cell = function (index, time) { + 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 + h/2); + var scroll_value = st + ct - (t + .01 * percent * h); this.scroll_manager.element.animate({scrollTop:scroll_value}, time); return scroll_value; };