From 21bbe1d11a2ff27f0e5a5f5838ea4e87947a3149 Mon Sep 17 00:00:00 2001 From: Vivian Fang Date: Wed, 6 Apr 2016 17:14:46 -0700 Subject: [PATCH 1/3] adding an action for toggling all line numbers, with keyboard shortcut Shift-L --- notebook/static/notebook/js/actions.js | 8 ++++++++ notebook/static/notebook/js/keyboardmanager.js | 1 + notebook/static/notebook/js/maintoolbar.js | 1 + notebook/static/notebook/js/notebook.js | 12 ++++++++++++ 4 files changed, 22 insertions(+) diff --git a/notebook/static/notebook/js/actions.js b/notebook/static/notebook/js/actions.js index 83df33bee..0c479f5bb 100644 --- a/notebook/static/notebook/js/actions.js +++ b/notebook/static/notebook/js/actions.js @@ -456,6 +456,14 @@ define(function(require){ env.notebook.show_command_palette(); } }, + 'toggle-all-line-numbers': { + help : 'toggles line numbers in all cells', + icon: 'fa-list-ol', + handler: function(env) { + console.log('calling function'); + env.notebook.toggle_all_line_numbers(); + } + }, 'toggle-toolbar':{ help: 'hide/show the toolbar', handler : function(env){ diff --git a/notebook/static/notebook/js/keyboardmanager.js b/notebook/static/notebook/js/keyboardmanager.js index 4edb29935..f2598db23 100644 --- a/notebook/static/notebook/js/keyboardmanager.js +++ b/notebook/static/notebook/js/keyboardmanager.js @@ -159,6 +159,7 @@ define([ 'o' : 'jupyter-notebook:toggle-cell-output-collapsed', 's' : 'jupyter-notebook:save-notebook', 'l' : 'jupyter-notebook:toggle-cell-line-numbers', + 'shift-l' : 'jupyter-notebook:toggle-all-line-numbers', 'h' : 'jupyter-notebook:show-keyboard-shortcuts', 'z' : 'jupyter-notebook:undo-cell-deletion', 'q' : 'jupyter-notebook:close-pager', diff --git a/notebook/static/notebook/js/maintoolbar.js b/notebook/static/notebook/js/maintoolbar.js index f449afa17..4ee0b2ce2 100644 --- a/notebook/static/notebook/js/maintoolbar.js +++ b/notebook/static/notebook/js/maintoolbar.js @@ -55,6 +55,7 @@ define([ 'run_int'], [''], [['jupyter-notebook:show-command-palette']], + [['jupyter-notebook:toggle-all-line-numbers']], [''] ]; this.construct(grps); diff --git a/notebook/static/notebook/js/notebook.js b/notebook/static/notebook/js/notebook.js index 250db8bf8..843566b52 100644 --- a/notebook/static/notebook/js/notebook.js +++ b/notebook/static/notebook/js/notebook.js @@ -65,6 +65,7 @@ define(function (require) { this.ws_url = options.ws_url; this._session_starting = false; this.last_modified = null; + this.line_numbers = false; // debug 484 this._last_modified = 'init'; // Firefox workaround @@ -552,6 +553,17 @@ define(function (require) { } return result; }; + + /** + * Toggles the display of line numbers in all cells. + */ + Notebook.prototype.toggle_all_line_numbers = function () { + this.line_numbers = !this.line_numbers; + var display = this.line_numbers; + this.get_cells().map(function(c) { + c.code_mirror.setOption('lineNumbers', display); + }) + } /** * Get the cell above a given cell. From ac526c2b552062bfc4dd9f3dcd36f8f13dbf4597 Mon Sep 17 00:00:00 2001 From: Grant Nestor Date: Wed, 10 Aug 2016 18:50:38 -0700 Subject: [PATCH 2/3] Move toggle line numbers from toolbar to "View" menu --- notebook/static/notebook/js/maintoolbar.js | 1 - notebook/static/notebook/js/menubar.js | 1 + notebook/templates/notebook.html | 10 ++++++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/notebook/static/notebook/js/maintoolbar.js b/notebook/static/notebook/js/maintoolbar.js index 4ee0b2ce2..f449afa17 100644 --- a/notebook/static/notebook/js/maintoolbar.js +++ b/notebook/static/notebook/js/maintoolbar.js @@ -55,7 +55,6 @@ define([ 'run_int'], [''], [['jupyter-notebook:show-command-palette']], - [['jupyter-notebook:toggle-all-line-numbers']], [''] ]; this.construct(grps); diff --git a/notebook/static/notebook/js/menubar.js b/notebook/static/notebook/js/menubar.js index 04984803a..5b032d06a 100644 --- a/notebook/static/notebook/js/menubar.js +++ b/notebook/static/notebook/js/menubar.js @@ -211,6 +211,7 @@ define([ '#move_cell_down': 'move-cell-down', '#toggle_header': 'toggle-header', '#toggle_toolbar': 'toggle-toolbar', + '#toggle_line_numbers': 'toggle-all-line-numbers', '#insert_cell_above': 'insert-cell-above', '#insert_cell_below': 'insert-cell-below', '#run_cell': 'run-cell', diff --git a/notebook/templates/notebook.html b/notebook/templates/notebook.html index f8e4f3c07..52cb74cec 100644 --- a/notebook/templates/notebook.html +++ b/notebook/templates/notebook.html @@ -154,10 +154,16 @@ data-notebook-path="{{notebook_path | urlencode}}"