From 21bbe1d11a2ff27f0e5a5f5838ea4e87947a3149 Mon Sep 17 00:00:00 2001 From: Vivian Fang Date: Wed, 6 Apr 2016 17:14:46 -0700 Subject: [PATCH] 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 83df33beeb..0c479f5bb6 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 4edb299357..f2598db23e 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 f449afa173..4ee0b2ce2a 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 250db8bf8e..843566b52f 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.