From b382950432e314fd5123ec0318b8e9d337982cdd Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Tue, 8 Dec 2015 21:19:10 +0100 Subject: [PATCH 1/3] Toggle scroll, collapse and clear cell now apply on selection. Still need tests. And as discussed a long time ago, the concept of toggling scrolling and Collapsed is **not** the right one, it leads to inconsistencies. The cell output has 3 states: - expanded - scrolled - collapsed And the menu action should decide which one of the 3 user want. Otherwise you get into inconsistencies like what is the difference between collapsed & scrolled /vs/ collapsed & not scrolled. Partially addresses #800 and #801 (I think) --- notebook/static/notebook/js/actions.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/notebook/static/notebook/js/actions.js b/notebook/static/notebook/js/actions.js index b39a68902..c049aa806 100644 --- a/notebook/static/notebook/js/actions.js +++ b/notebook/static/notebook/js/actions.js @@ -307,22 +307,33 @@ define(function(require){ } }, 'toggle-cell-output-collapsed' : { - help : 'toggle output', + help : 'toggle output of selected cells', help_index : 'gb', handler : function (env) { - env.notebook.toggle_output(); + var indices = env.notebook.get_selected_cells_indices(); + console.log(indices) + for(var i =0; i< indices.length; i++){ + env.notebook.toggle_output(indices[i]); + } } }, 'toggle-cell-output-scrolled' : { - help : 'toggle output scrolling', + help : 'toggle output scrolling of selected cells', help_index : 'gc', handler : function (env) { - env.notebook.toggle_output_scroll(); + var indices = env.notebook.get_selected_cells_indices(); + for(var i =0; i< indices.length; i++){ + env.notebook.toggle_output_scroll(indices[i]); + } } }, 'clear-cell-output' : { + help : 'clear output of selected cells', handler : function (env) { - env.notebook.clear_output(); + var indices = env.notebook.get_selected_cells_indices(); + for(var i =0; i< indices.length; i++){ + env.notebook.clear_output(indices[i]); + } } }, 'move-cell-down' : { From 068f4e9136f6bdce6d5c208f95d0d95a4b6db64f Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Wed, 9 Dec 2015 22:35:01 -0600 Subject: [PATCH 2/3] Refactored multiselect toggles --- notebook/static/notebook/js/actions.js | 16 ++------- notebook/static/notebook/js/notebook.js | 44 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/notebook/static/notebook/js/actions.js b/notebook/static/notebook/js/actions.js index c049aa806..7a40ec7e7 100644 --- a/notebook/static/notebook/js/actions.js +++ b/notebook/static/notebook/js/actions.js @@ -310,30 +310,20 @@ define(function(require){ help : 'toggle output of selected cells', help_index : 'gb', handler : function (env) { - var indices = env.notebook.get_selected_cells_indices(); - console.log(indices) - for(var i =0; i< indices.length; i++){ - env.notebook.toggle_output(indices[i]); - } + env.notebook.toggle_cells_outputs(); } }, 'toggle-cell-output-scrolled' : { help : 'toggle output scrolling of selected cells', help_index : 'gc', handler : function (env) { - var indices = env.notebook.get_selected_cells_indices(); - for(var i =0; i< indices.length; i++){ - env.notebook.toggle_output_scroll(indices[i]); - } + env.notebook.toggle_cells_outputs_scroll(); } }, 'clear-cell-output' : { help : 'clear output of selected cells', handler : function (env) { - var indices = env.notebook.get_selected_cells_indices(); - for(var i =0; i< indices.length; i++){ - env.notebook.clear_output(indices[i]); - } + env.notebook.clear_cells_outputs(); } }, 'move-cell-down' : { diff --git a/notebook/static/notebook/js/notebook.js b/notebook/static/notebook/js/notebook.js index 14c8b42aa..d4fb425d8 100644 --- a/notebook/static/notebook/js/notebook.js +++ b/notebook/static/notebook/js/notebook.js @@ -1600,6 +1600,20 @@ define(function (require) { } }; + /** + * Clear multiple selected CodeCells' output areas. + * + */ + Notebook.prototype.clear_cells_outputs = function(indices) { + if (!indices) { + var indices = this.get_selected_cells_indices(); + } + + for (var i = 0; i < indices.length; i++){ + this.clear_output(indices[i]); + } + } + /** * Clear each code cell's output area. */ @@ -1653,6 +1667,21 @@ define(function (require) { } }; + /** + * Toggle whether all selected cells' outputs are collapsed or expanded. + * + * @param {integer} indices - the indices of the cells to toggle + */ + Notebook.prototype.toggle_cells_outputs = function(indices) { + if (!indices) { + var indices = this.get_selected_cells_indices(); + } + + for (var i = 0; i < indices.length; i++){ + this.toggle_output(indices[i]); + } + } + /** * Toggle the output of all cells. */ @@ -1680,6 +1709,21 @@ define(function (require) { } }; + /** + * Toggle a scrollbar for selected long cells' outputs. + * + * @param {integer} indices - the indices of the cells to toggle + */ + Notebook.prototype.toggle_cells_outputs_scroll = function(indices) { + if (!indices) { + var indices = this.get_selected_cells_indices(); + } + + for (var i = 0; i < indices.length; i++){ + this.toggle_output_scroll(indices[i]); + } + } + /** * Toggle the scrolling of long output on all cells. */ From ca496ee2680560f241aeb6e60e476f752e75ca6e Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Wed, 9 Dec 2015 22:35:39 -0600 Subject: [PATCH 3/3] Added tests for multiselect toggle functionality --- notebook/tests/notebook/multiselect_toggle.js | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 notebook/tests/notebook/multiselect_toggle.js diff --git a/notebook/tests/notebook/multiselect_toggle.js b/notebook/tests/notebook/multiselect_toggle.js new file mode 100644 index 000000000..1aff8cc66 --- /dev/null +++ b/notebook/tests/notebook/multiselect_toggle.js @@ -0,0 +1,70 @@ +// Test +casper.notebook_test(function () { + var that = this; + + var a = 'print("a")'; + var index = this.append_cell(a); + + var b = 'print("b")'; + index = this.append_cell(b); + + var c = 'print("c")'; + index = this.append_cell(c); + + this.then(function () { + /** + * Test that cells, which start off not collapsed, are collapsed after + * calling the multiselected cell toggle. + */ + var cell_output_states = this.evaluate(function() { + Jupyter.notebook.select(0); + Jupyter.notebook.extend_selection_by(2); + var indices = Jupyter.notebook.get_selected_cells_indices(); + Jupyter.notebook.toggle_cells_outputs(); + return indices.map(function(index) { + return Jupyter.notebook.get_cell(index).collapsed; + }); + }); + + this.test.assert(cell_output_states.every(function(cell_output_state) { + return cell_output_state == false; + }), "ensure that all cells are not collapsed"); + + /** + * Test that cells, which start off not scrolled are scrolled after + * calling the multiselected scroll toggle. + */ + var cell_scrolled_states = this.evaluate(function() { + Jupyter.notebook.select(0); + Jupyter.notebook.extend_selection_by(2); + var indices = Jupyter.notebook.get_selected_cells_indices(); + Jupyter.notebook.toggle_cells_outputs_scroll(); + return indices.map(function(index) { + return Jupyter.notebook.get_cell(index).output_area.scroll_state; + }); + }); + + this.test.assert(cell_scrolled_states.every(function(cell_scroll_state) { + return cell_scroll_state; + }), "ensure that all have scrolling enabled"); + + /** + * Test that cells, which start off not cleared are cleared after + * calling the multiselected scroll toggle. + */ + var cell_outputs_cleared = this.evaluate(function() { + Jupyter.notebook.select(0); + Jupyter.notebook.extend_selection_by(2); + var indices = Jupyter.notebook.get_selected_cells_indices(); + Jupyter.notebook.clear_cells_outputs(); + return indices.map(function(index) { + return Jupyter.notebook.get_cell(index).output_area.element.html(); + }); + }); + + this.test.assert(cell_outputs_cleared.every(function(cell_output_state) { + return cell_output_state == ""; + }), "ensure that all cells are cleared"); + + }); +});