Skip to content

Commit 21bbe1d

Browse files
committed
adding an action for toggling all line numbers, with keyboard shortcut Shift-L
1 parent f49197c commit 21bbe1d

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

notebook/static/notebook/js/actions.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,14 @@ define(function(require){
456456
env.notebook.show_command_palette();
457457
}
458458
},
459+
'toggle-all-line-numbers': {
460+
help : 'toggles line numbers in all cells',
461+
icon: 'fa-list-ol',
462+
handler: function(env) {
463+
console.log('calling function');
464+
env.notebook.toggle_all_line_numbers();
465+
}
466+
},
459467
'toggle-toolbar':{
460468
help: 'hide/show the toolbar',
461469
handler : function(env){

notebook/static/notebook/js/keyboardmanager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ define([
159159
'o' : 'jupyter-notebook:toggle-cell-output-collapsed',
160160
's' : 'jupyter-notebook:save-notebook',
161161
'l' : 'jupyter-notebook:toggle-cell-line-numbers',
162+
'shift-l' : 'jupyter-notebook:toggle-all-line-numbers',
162163
'h' : 'jupyter-notebook:show-keyboard-shortcuts',
163164
'z' : 'jupyter-notebook:undo-cell-deletion',
164165
'q' : 'jupyter-notebook:close-pager',

notebook/static/notebook/js/maintoolbar.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ define([
5555
'run_int'],
5656
['<add_celltype_list>'],
5757
[['jupyter-notebook:show-command-palette']],
58+
[['jupyter-notebook:toggle-all-line-numbers']],
5859
['<add_celltoolbar_reminder>']
5960
];
6061
this.construct(grps);

notebook/static/notebook/js/notebook.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ define(function (require) {
6565
this.ws_url = options.ws_url;
6666
this._session_starting = false;
6767
this.last_modified = null;
68+
this.line_numbers = false;
6869
// debug 484
6970
this._last_modified = 'init';
7071
// Firefox workaround
@@ -552,6 +553,17 @@ define(function (require) {
552553
}
553554
return result;
554555
};
556+
557+
/**
558+
* Toggles the display of line numbers in all cells.
559+
*/
560+
Notebook.prototype.toggle_all_line_numbers = function () {
561+
this.line_numbers = !this.line_numbers;
562+
var display = this.line_numbers;
563+
this.get_cells().map(function(c) {
564+
c.code_mirror.setOption('lineNumbers', display);
565+
})
566+
}
555567

556568
/**
557569
* Get the cell above a given cell.

0 commit comments

Comments
 (0)