Skip to content

Commit 14089ce

Browse files
Carreaugnestor
authored andcommitted
Inherit configuration and propagate it from MD cell
Persist the configuration of toggling in nbconfig.
1 parent ac526c2 commit 14089ce

File tree

5 files changed

+44
-15
lines changed

5 files changed

+44
-15
lines changed

notebook/static/notebook/js/actions.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,12 +462,23 @@ define(function(require){
462462
env.notebook.show_command_palette();
463463
}
464464
},
465+
'show-all-line-numbers': {
466+
help : 'show line numbers in all cells, and persist the setting',
467+
handler: function(env) {
468+
env.notebook.line_numbers = true;
469+
}
470+
},
471+
'hide-all-line-numbers': {
472+
help : 'hide line numbers in all cells, and persist the setting',
473+
handler: function(env) {
474+
env.notebook.line_numbers = false;
475+
}
476+
},
465477
'toggle-all-line-numbers': {
466-
help : 'toggles line numbers in all cells',
478+
help : 'toggles line numbers in all cells, and persist the setting',
467479
icon: 'fa-list-ol',
468480
handler: function(env) {
469-
console.log('calling function');
470-
env.notebook.toggle_all_line_numbers();
481+
env.notebook.line_numbers = !env.notebook.line_numbers;
471482
}
472483
},
473484
'toggle-toolbar':{

notebook/static/notebook/js/cell.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ define([
1414
'codemirror/lib/codemirror',
1515
'codemirror/addon/edit/matchbrackets',
1616
'codemirror/addon/edit/closebrackets',
17-
'codemirror/addon/comment/comment'
18-
], function(utils, CodeMirror, cm_match, cm_closeb, cm_comment) {
17+
'codemirror/addon/comment/comment',
18+
'services/config',
19+
], function(utils, CodeMirror, cm_match, cm_closeb, cm_comment, configmod) {
1920
"use strict";
2021

2122
var overlayHack = CodeMirror.scrollbarModel.native.prototype.overlayHack;
@@ -87,7 +88,12 @@ define([
8788
if(this.class_config){
8889
_local_cm_config = this.class_config.get_sync('cm_config');
8990
}
90-
config.cm_config = utils.mergeopt({}, config.cm_config, _local_cm_config);
91+
92+
var local = new configmod.ConfigWithDefaults(options.config,
93+
{}, 'Cell');
94+
var llcm = local.get_sync('cm_config');
95+
96+
config.cm_config = utils.mergeopt({}, config.cm_config, utils.mergeopt({}, llcm, _local_cm_config));
9197
this.cell_id = utils.uuid();
9298
this._options = config;
9399

notebook/static/notebook/js/codecell.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ define([
108108
this.completer = null;
109109

110110
Cell.apply(this,[{
111-
config: $.extend({}, CodeCell.options_default),
111+
config: options.config,
112112
keyboard_manager: options.keyboard_manager,
113113
events: this.events}]);
114114

notebook/static/notebook/js/notebook.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ import {ShortcutEditor} from 'notebook/js/shortcuteditor';
6565
this.ws_url = options.ws_url;
6666
this._session_starting = false;
6767
this.last_modified = null;
68-
this.line_numbers = false;
6968
// debug 484
7069
this._last_modified = 'init';
7170
// Firefox workaround
@@ -162,11 +161,28 @@ import {ShortcutEditor} from 'notebook/js/shortcuteditor';
162161
slideshow_celltoolbar.register(this);
163162
attachments_celltoolbar.register(this);
164163

164+
var that = this;
165+
166+
Object.defineProperty(this, 'line_numbers', {
167+
get: function(){
168+
var d = that.config.data||{}
169+
var cmc = (d['Cell']||{})['cm_config']||{}
170+
return cmc['lineNumbers'] || false;
171+
},
172+
set: function(value){
173+
this.get_cells().map(function(c) {
174+
c.code_mirror.setOption('lineNumbers', value);
175+
})
176+
that.config.update({'Cell':{'cm_config':{'lineNumbers':value}}})
177+
}
178+
179+
})
165180
// prevent assign to miss-typed properties.
166181
Object.seal(this);
167182
};
168183

169184

185+
170186
Notebook.options_default = {
171187
// can be any cell type, or the special values of
172188
// 'above', 'below', or 'selected' to get the value from another cell.
@@ -564,10 +580,6 @@ import {ShortcutEditor} from 'notebook/js/shortcuteditor';
564580
*/
565581
Notebook.prototype.toggle_all_line_numbers = function () {
566582
this.line_numbers = !this.line_numbers;
567-
var display = this.line_numbers;
568-
this.get_cells().map(function(c) {
569-
c.code_mirror.setOption('lineNumbers', display);
570-
})
571583
}
572584

573585
/**

notebook/static/notebook/js/textcell.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ define([
5858
// we cannot put this as a class key as it has handle to "this".
5959
var config = utils.mergeopt(TextCell, this.config);
6060
Cell.apply(this, [{
61-
config: config,
61+
config: options.config,
6262
keyboard_manager: options.keyboard_manager,
6363
events: this.events}]);
6464

@@ -282,7 +282,7 @@ define([
282282
var config = utils.mergeopt(MarkdownCell, {});
283283
this.class_config = new configmod.ConfigWithDefaults(options.config,
284284
{}, 'MarkdownCell');
285-
TextCell.apply(this, [$.extend({}, options, {config: config})]);
285+
TextCell.apply(this, [$.extend({}, options, {config: options.config})]);
286286

287287
this.cell_type = 'markdown';
288288

@@ -528,7 +528,7 @@ define([
528528
*/
529529
options = options || {};
530530
var config = utils.mergeopt(RawCell, {});
531-
TextCell.apply(this, [$.extend({}, options, {config: config})]);
531+
TextCell.apply(this, [$.extend({}, options, {config: options.config})]);
532532

533533
this.class_config = new configmod.ConfigWithDefaults(options.config,
534534
RawCell.config_defaults, 'RawCell');

0 commit comments

Comments
 (0)