From 3997769defff4ae3041827497d5a8ada4662de80 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Sat, 27 Sep 2014 15:57:01 -0400 Subject: [PATCH 1/2] Fixed off by one error in get_prev_cell Not sure why this was a TODO. Maybe `find_cell_index()` returned zero at one time, but in the browsers I tested, it always returns null if not found. --- IPython/html/static/notebook/js/notebook.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index ac8b220a3..522216881 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -465,11 +465,9 @@ define([ * @return {Cell} The previous cell */ Notebook.prototype.get_prev_cell = function (cell) { - // TODO: off-by-one - // nb.get_prev_cell(nb.get_cell(1)) is null var result = null; var index = this.find_cell_index(cell); - if (index !== null && index > 1) { + if (index !== null && index > 0) { result = this.get_cell(index-1); } return result; From 6c3d40bbcd438d974c8b4356f2453738de7abb9a Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Sun, 28 Sep 2014 14:01:35 -0400 Subject: [PATCH 2/2] Update documentation for functions that can return null --- IPython/html/static/notebook/js/notebook.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index 522216881..7e17848da 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -430,7 +430,7 @@ define([ * * @method get_cell * @param {Number} index An index of a cell to retrieve - * @return {Cell} A particular cell + * @return {Cell} Cell or null if no cell was found. */ Notebook.prototype.get_cell = function (index) { var result = null; @@ -446,7 +446,7 @@ define([ * * @method get_next_cell * @param {Cell} cell The provided cell - * @return {Cell} The next cell + * @return {Cell} the next cell or null if no cell was found. */ Notebook.prototype.get_next_cell = function (cell) { var result = null; @@ -462,7 +462,7 @@ define([ * * @method get_prev_cell * @param {Cell} cell The provided cell - * @return {Cell} The previous cell + * @return {Cell} The previous cell or null if no cell was found. */ Notebook.prototype.get_prev_cell = function (cell) { var result = null; @@ -478,7 +478,7 @@ define([ * * @method find_cell_index * @param {Cell} cell The provided cell - * @return {Number} The cell's numeric index + * @return {Number} The cell's numeric index or null if no cell was found. */ Notebook.prototype.find_cell_index = function (cell) { var result = null;