From a197d4f7f4e0ac0aa10b84cda1aabaadf48a7628 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Wed, 13 May 2015 09:44:26 -0700 Subject: [PATCH] Store codemirror config in only one location Closes (once backported) #EntropyOrg/p5-Devel-IPerl#40 and jupyter/notebook#88 --- jupyter_notebook/static/notebook/js/cell.js | 11 ++++++++++- jupyter_notebook/static/notebook/js/codecell.js | 4 ++-- jupyter_notebook/static/notebook/js/notebook.js | 2 +- jupyter_notebook/static/notebook/js/textcell.js | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/jupyter_notebook/static/notebook/js/cell.js b/jupyter_notebook/static/notebook/js/cell.js index 7e9bc460b..4e34e2eec 100644 --- a/jupyter_notebook/static/notebook/js/cell.js +++ b/jupyter_notebook/static/notebook/js/cell.js @@ -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 ? this.user_highlight = 'auto'; + var _local_cm_config = {}; if(this.class_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._options = config; diff --git a/jupyter_notebook/static/notebook/js/codecell.js b/jupyter_notebook/static/notebook/js/codecell.js index 6a34f8537..a3d7fd227 100644 --- a/jupyter_notebook/static/notebook/js/codecell.js +++ b/jupyter_notebook/static/notebook/js/codecell.js @@ -123,7 +123,7 @@ define([ "Cmd-/" : "toggleComment", "Ctrl-/" : "toggleComment" }, - mode: 'ipython', + mode: 'text', theme: 'ipython', matchBrackets: true, autoCloseBrackets: true @@ -162,7 +162,7 @@ define([ notebook: this.notebook}); inner_cell.append(this.celltoolbar.element); var input_area = $('
').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, // ensure KM is enabled when CodeMirror is focused: this.code_mirror.on('focus', function () { diff --git a/jupyter_notebook/static/notebook/js/notebook.js b/jupyter_notebook/static/notebook/js/notebook.js index db3519e54..808e530b9 100644 --- a/jupyter_notebook/static/notebook/js/notebook.js +++ b/jupyter_notebook/static/notebook/js/notebook.js @@ -1526,7 +1526,7 @@ define(function (require) { // This is currently redundant, because cm_config ends up as // codemirror's own .options object, but I don't want to // rely on that. - cell.cm_config.mode = spec; + cell._options.cm_config.mode = spec; } }); diff --git a/jupyter_notebook/static/notebook/js/textcell.js b/jupyter_notebook/static/notebook/js/textcell.js index ce01ce8d8..a8a6c11b8 100644 --- a/jupyter_notebook/static/notebook/js/textcell.js +++ b/jupyter_notebook/static/notebook/js/textcell.js @@ -98,7 +98,7 @@ define([ notebook: this.notebook}); inner_cell.append(this.celltoolbar.element); var input_area = $('
').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, // ensure KM is enabled when CodeMirror is focused: this.code_mirror.on('focus', function () {