diff --git a/notebook/static/notebook/js/actions.js b/notebook/static/notebook/js/actions.js index 601675676..d61e9ee75 100644 --- a/notebook/static/notebook/js/actions.js +++ b/notebook/static/notebook/js/actions.js @@ -462,6 +462,25 @@ define(function(require){ env.notebook.show_command_palette(); } }, + 'show-all-line-numbers': { + help : 'show line numbers in all cells, and persist the setting', + handler: function(env) { + env.notebook.line_numbers = true; + } + }, + 'hide-all-line-numbers': { + help : 'hide line numbers in all cells, and persist the setting', + handler: function(env) { + env.notebook.line_numbers = false; + } + }, + 'toggle-all-line-numbers': { + help : 'toggles line numbers in all cells, and persist the setting', + icon: 'fa-list-ol', + handler: function(env) { + env.notebook.line_numbers = !env.notebook.line_numbers; + } + }, 'toggle-toolbar':{ help: 'hide/show the toolbar', handler : function(env){ diff --git a/notebook/static/notebook/js/cell.js b/notebook/static/notebook/js/cell.js index d94501389..9b6379a68 100644 --- a/notebook/static/notebook/js/cell.js +++ b/notebook/static/notebook/js/cell.js @@ -14,8 +14,9 @@ define([ 'codemirror/lib/codemirror', 'codemirror/addon/edit/matchbrackets', 'codemirror/addon/edit/closebrackets', - 'codemirror/addon/comment/comment' -], function(utils, CodeMirror, cm_match, cm_closeb, cm_comment) { + 'codemirror/addon/comment/comment', + 'services/config', +], function(utils, CodeMirror, cm_match, cm_closeb, cm_comment, configmod) { "use strict"; var overlayHack = CodeMirror.scrollbarModel.native.prototype.overlayHack; @@ -87,7 +88,12 @@ define([ if(this.class_config){ _local_cm_config = this.class_config.get_sync('cm_config'); } - config.cm_config = utils.mergeopt({}, config.cm_config, _local_cm_config); + + var local = new configmod.ConfigWithDefaults(options.config, + {}, 'Cell'); + var llcm = local.get_sync('cm_config'); + + config.cm_config = utils.mergeopt({}, config.cm_config, utils.mergeopt({}, llcm, _local_cm_config)); this.cell_id = utils.uuid(); this._options = config; diff --git a/notebook/static/notebook/js/codecell.js b/notebook/static/notebook/js/codecell.js index 6be236899..ef69791c1 100644 --- a/notebook/static/notebook/js/codecell.js +++ b/notebook/static/notebook/js/codecell.js @@ -108,7 +108,7 @@ define([ this.completer = null; Cell.apply(this,[{ - config: $.extend({}, CodeCell.options_default), + config: options.config, keyboard_manager: options.keyboard_manager, events: this.events}]); diff --git a/notebook/static/notebook/js/keyboardmanager.js b/notebook/static/notebook/js/keyboardmanager.js index 411b53fad..d1b76a977 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/menubar.js b/notebook/static/notebook/js/menubar.js index e82ffbe7d..f3779f5af 100644 --- a/notebook/static/notebook/js/menubar.js +++ b/notebook/static/notebook/js/menubar.js @@ -264,6 +264,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/static/notebook/js/notebook.js b/notebook/static/notebook/js/notebook.js index 2069c81fb..268c39275 100644 --- a/notebook/static/notebook/js/notebook.js +++ b/notebook/static/notebook/js/notebook.js @@ -161,11 +161,28 @@ import {ShortcutEditor} from 'notebook/js/shortcuteditor'; slideshow_celltoolbar.register(this); attachments_celltoolbar.register(this); + var that = this; + + Object.defineProperty(this, 'line_numbers', { + get: function(){ + var d = that.config.data||{} + var cmc = (d['Cell']||{})['cm_config']||{} + return cmc['lineNumbers'] || false; + }, + set: function(value){ + this.get_cells().map(function(c) { + c.code_mirror.setOption('lineNumbers', value); + }) + that.config.update({'Cell':{'cm_config':{'lineNumbers':value}}}) + } + + }) // prevent assign to miss-typed properties. Object.seal(this); }; + Notebook.options_default = { // can be any cell type, or the special values of // 'above', 'below', or 'selected' to get the value from another cell. @@ -555,6 +572,13 @@ import {ShortcutEditor} from 'notebook/js/shortcuteditor'; } return result; }; + + /** + * Toggles the display of line numbers in all cells. + */ + Notebook.prototype.toggle_all_line_numbers = function () { + this.line_numbers = !this.line_numbers; + } /** * Get the cell above a given cell. diff --git a/notebook/static/notebook/js/textcell.js b/notebook/static/notebook/js/textcell.js index abb6d9b1d..9ba54b4ae 100644 --- a/notebook/static/notebook/js/textcell.js +++ b/notebook/static/notebook/js/textcell.js @@ -58,7 +58,7 @@ define([ // we cannot put this as a class key as it has handle to "this". var config = utils.mergeopt(TextCell, this.config); Cell.apply(this, [{ - config: config, + config: options.config, keyboard_manager: options.keyboard_manager, events: this.events}]); @@ -282,7 +282,7 @@ define([ var config = utils.mergeopt(MarkdownCell, {}); this.class_config = new configmod.ConfigWithDefaults(options.config, {}, 'MarkdownCell'); - TextCell.apply(this, [$.extend({}, options, {config: config})]); + TextCell.apply(this, [$.extend({}, options, {config: options.config})]); this.cell_type = 'markdown'; @@ -528,7 +528,7 @@ define([ */ options = options || {}; var config = utils.mergeopt(RawCell, {}); - TextCell.apply(this, [$.extend({}, options, {config: config})]); + TextCell.apply(this, [$.extend({}, options, {config: options.config})]); this.class_config = new configmod.ConfigWithDefaults(options.config, RawCell.config_defaults, 'RawCell'); diff --git a/notebook/templates/notebook.html b/notebook/templates/notebook.html index 8ac71de66..ad95449ed 100644 --- a/notebook/templates/notebook.html +++ b/notebook/templates/notebook.html @@ -157,10 +157,16 @@ data-notebook-path="{{notebook_path | urlencode}}"