diff --git a/IPython/frontend/html/notebook/static/js/cell.js b/IPython/frontend/html/notebook/static/js/cell.js index d49e456..83d855c 100644 --- a/IPython/frontend/html/notebook/static/js/cell.js +++ b/IPython/frontend/html/notebook/static/js/cell.js @@ -22,12 +22,20 @@ var IPython = (function (IPython) { /** * The Base `Cell` class from which to inherit * @class Cell - */ + **/ /* * @constructor + * + * @param {object|undefined} [options] + * @param [options.cm_config] {object} config to pass to CodeMirror, will extend default parameters */ - var Cell = function () { + var Cell = function (options) { + + options = options || {}; + // superclass default overwrite our default + this.cm_config = $.extend({},Cell.cm_default,options.cm_config); + this.placeholder = this.placeholder || ''; this.read_only = false; this.selected = false; @@ -43,6 +51,11 @@ var IPython = (function (IPython) { this.cell_id = utils.uuid(); }; + Cell.cm_default = { + indentUnit : 4, + readOnly: this.read_only, + }; + /** * Empty. Subclasses must implement create_element. @@ -240,7 +253,7 @@ var IPython = (function (IPython) { }; /** - * force codemirror highlight mode + * Force codemirror highlight mode * @method force_highlight * @param {object} - CodeMirror mode **/ diff --git a/IPython/frontend/html/notebook/static/js/codecell.js b/IPython/frontend/html/notebook/static/js/codecell.js index 68db4c8..d3b25ea 100644 --- a/IPython/frontend/html/notebook/static/js/codecell.js +++ b/IPython/frontend/html/notebook/static/js/codecell.js @@ -58,14 +58,30 @@ var IPython = (function (IPython) { * * @constructor * @param {Object|null} kernel + * @param {object|undefined} [options] + * @param [options.cm_config] {object} config to pass to CodeMirror */ - var CodeCell = function (kernel) { + var CodeCell = function (kernel, options) { + var options = options || {} this.kernel = kernel || null; this.code_mirror = null; this.input_prompt_number = null; this.collapsed = false; this.default_mode = 'python'; - IPython.Cell.apply(this, arguments); + + + var cm_overwrite_options = { + extraKeys: {"Tab": "indentMore","Shift-Tab" : "indentLess",'Backspace':"delSpaceToPrevTabStop"}, + onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this) + }; + + var arg_cm_options = options.cm_options || {}; + var cm_config = $.extend({},CodeCell.cm_default, arg_cm_options, cm_overwrite_options); + + var options = {}; + options.cm_config = cm_config; + + IPython.Cell.apply(this,[options]); var that = this; this.element.focusout( @@ -73,6 +89,13 @@ var IPython = (function (IPython) { ); }; + CodeCell.cm_default = { + mode: 'python', + theme: 'ipython', + matchBrackets: true + }; + + CodeCell.prototype = new IPython.Cell(); /** @@ -96,15 +119,7 @@ var IPython = (function (IPython) { input.append($('<div/>').addClass('prompt input_prompt')); vbox.append(this.celltoolbar.element); var input_area = $('<div/>').addClass('input_area'); - this.code_mirror = CodeMirror(input_area.get(0), { - indentUnit : 4, - mode: 'python', - theme: 'ipython', - readOnly: this.read_only, - extraKeys: {"Tab": "indentMore","Shift-Tab" : "indentLess",'Backspace':"delSpaceToPrevTabStop"}, - onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this), - matchBrackets: true - }); + this.code_mirror = CodeMirror(input_area.get(0), this.cm_config); vbox.append(input_area); input.append(vbox); var output = $('<div></div>'); diff --git a/IPython/frontend/html/notebook/static/js/textcell.js b/IPython/frontend/html/notebook/static/js/textcell.js index fdae47f..65d96a0 100644 --- a/IPython/frontend/html/notebook/static/js/textcell.js +++ b/IPython/frontend/html/notebook/static/js/textcell.js @@ -26,14 +26,38 @@ var IPython = (function (IPython) { * @class TextCell * @constructor TextCell * @extend Ipython.Cell + * @param {object|undefined} [options] + * @param [options.cm_config] {object} config to pass to CodeMirror, will extend/overwrite default config */ - var TextCell = function () { + var TextCell = function (options) { this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed'; - IPython.Cell.apply(this, arguments); + var options = options || {}; + + var cm_overwrite_options = { + extraKeys: {"Tab": "indentMore","Shift-Tab" : "indentLess"}, + onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this) + }; + + var arg_cm_options = options.cm_options || {}; + var cm_config = $.extend({},TextCell.cm_default, arg_cm_options, cm_overwrite_options); + + var options = {}; + options.cm_config = cm_config; + + + IPython.Cell.apply(this, [options]); this.rendered = false; this.cell_type = this.cell_type || 'text'; }; + TextCell.cm_default = { + mode: this.code_mirror_mode, + theme: 'default', + value: this.placeholder, + lineWrapping : true, + } + + TextCell.prototype = new IPython.Cell(); /** @@ -50,16 +74,7 @@ var IPython = (function (IPython) { cell.append(this.celltoolbar.element); var input_area = $('<div/>').addClass('text_cell_input border-box-sizing'); - this.code_mirror = CodeMirror(input_area.get(0), { - indentUnit : 4, - mode: this.code_mirror_mode, - theme: 'default', - value: this.placeholder, - readOnly: this.read_only, - lineWrapping : true, - extraKeys: {"Tab": "indentMore","Shift-Tab" : "indentLess"}, - onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this) - }); + this.code_mirror = CodeMirror(input_area.get(0), this.cm_config); // The tabindex=-1 makes this div focusable. var render_area = $('<div/>').addClass('text_cell_render border-box-sizing'). addClass('rendered_html').attr('tabindex','-1');