Store codemirror config in only one location

Closes (once backported) #EntropyOrg/p5-Devel-IPerl#40
and jupyter/notebook#88
This commit is contained in:
Matthias Bussonnier 2015-05-13 09:44:26 -07:00
parent 4be2c7957a
commit a197d4f7f4
4 changed files with 14 additions and 5 deletions

View File

@ -73,14 +73,23 @@ define([
} }
}); });
// backward compat.
Object.defineProperty(this, 'cm_config', {
get: function() {
console.warn("warning you are accessing a deprecated field")
return that._options.cm_config;
},
});
// load this from metadata later ? // load this from metadata later ?
this.user_highlight = 'auto'; this.user_highlight = 'auto';
var _local_cm_config = {}; var _local_cm_config = {};
if(this.class_config){ if(this.class_config){
_local_cm_config = this.class_config.get_sync('cm_config'); _local_cm_config = this.class_config.get_sync('cm_config');
} }
this.cm_config = utils.mergeopt({}, config.cm_config, _local_cm_config); config.cm_config = utils.mergeopt({}, config.cm_config, _local_cm_config);
this.cell_id = utils.uuid(); this.cell_id = utils.uuid();
this._options = config; this._options = config;

View File

@ -123,7 +123,7 @@ define([
"Cmd-/" : "toggleComment", "Cmd-/" : "toggleComment",
"Ctrl-/" : "toggleComment" "Ctrl-/" : "toggleComment"
}, },
mode: 'ipython', mode: 'text',
theme: 'ipython', theme: 'ipython',
matchBrackets: true, matchBrackets: true,
autoCloseBrackets: true autoCloseBrackets: true
@ -162,7 +162,7 @@ define([
notebook: this.notebook}); notebook: this.notebook});
inner_cell.append(this.celltoolbar.element); inner_cell.append(this.celltoolbar.element);
var input_area = $('<div/>').addClass('input_area'); var input_area = $('<div/>').addClass('input_area');
this.code_mirror = new CodeMirror(input_area.get(0), this.cm_config); this.code_mirror = new CodeMirror(input_area.get(0), this._options.cm_config);
// In case of bugs that put the keyboard manager into an inconsistent state, // In case of bugs that put the keyboard manager into an inconsistent state,
// ensure KM is enabled when CodeMirror is focused: // ensure KM is enabled when CodeMirror is focused:
this.code_mirror.on('focus', function () { this.code_mirror.on('focus', function () {

View File

@ -1526,7 +1526,7 @@ define(function (require) {
// This is currently redundant, because cm_config ends up as // This is currently redundant, because cm_config ends up as
// codemirror's own .options object, but I don't want to // codemirror's own .options object, but I don't want to
// rely on that. // rely on that.
cell.cm_config.mode = spec; cell._options.cm_config.mode = spec;
} }
}); });

View File

@ -98,7 +98,7 @@ define([
notebook: this.notebook}); notebook: this.notebook});
inner_cell.append(this.celltoolbar.element); inner_cell.append(this.celltoolbar.element);
var input_area = $('<div/>').addClass('input_area'); var input_area = $('<div/>').addClass('input_area');
this.code_mirror = new CodeMirror(input_area.get(0), this.cm_config); this.code_mirror = new CodeMirror(input_area.get(0), this._options.cm_config);
// In case of bugs that put the keyboard manager into an inconsistent state, // In case of bugs that put the keyboard manager into an inconsistent state,
// ensure KM is enabled when CodeMirror is focused: // ensure KM is enabled when CodeMirror is focused:
this.code_mirror.on('focus', function () { this.code_mirror.on('focus', function () {