From 490248ea930a0de1f9f65529c9f0b9f9ae04c277 Mon Sep 17 00:00:00 2001 From: Min RK Date: Tue, 13 Jan 2015 11:39:08 -0800 Subject: [PATCH] move auto_highlight to Cell consolidates nearly-identical CodeCell.auto_highlight and TextCell.auto_highlight --- IPython/html/static/notebook/js/cell.js | 12 ++++++++++-- IPython/html/static/notebook/js/codecell.js | 11 ++--------- IPython/html/static/notebook/js/textcell.js | 9 +-------- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/IPython/html/static/notebook/js/cell.js b/IPython/html/static/notebook/js/cell.js index a20202e42..e043153d6 100644 --- a/IPython/html/static/notebook/js/cell.js +++ b/IPython/html/static/notebook/js/cell.js @@ -516,7 +516,15 @@ define([ this.user_highlight = mode; this.auto_highlight(); }; - + + /** + * Trigger autodetection of highlight scheme for current cell + * @method auto_highlight + */ + Cell.prototype.auto_highlight = function () { + this._auto_highlight(this.class_config.get_sync('highlight_modes')); + }; + /** * Try to autodetect cell highlight mode, or use selected mode * @methods _auto_highlight @@ -655,7 +663,7 @@ define([ var cell = this; this.element.find('.inner_cell').find("a").click(function () { - cell.events.trigger('unrecognized_cell.Cell', {cell: cell}) + cell.events.trigger('unrecognized_cell.Cell', {cell: cell}); }); }; diff --git a/IPython/html/static/notebook/js/codecell.js b/IPython/html/static/notebook/js/codecell.js index 3d2e30be5..1404956f2 100644 --- a/IPython/html/static/notebook/js/codecell.js +++ b/IPython/html/static/notebook/js/codecell.js @@ -147,7 +147,7 @@ define([ }; CodeCell.config_defaults = { - cell_magic_highlight : { + highlight_modes : { 'magic_javascript' :{'reg':[/^%%javascript/]}, 'magic_perl' :{'reg':[/^%%perl/]}, 'magic_ruby' :{'reg':[/^%%ruby/]}, @@ -179,13 +179,6 @@ define([ } }; - /** - * @method auto_highlight - */ - CodeCell.prototype.auto_highlight = function () { - this._auto_highlight(this.class_config.get_sync('cell_magic_highlight')); - }; - /** @method create_element */ CodeCell.prototype.create_element = function () { Cell.prototype.create_element.apply(this, arguments); @@ -202,7 +195,7 @@ define([ 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.on('keydown', $.proxy(this.handle_keyevent,this)) + this.code_mirror.on('keydown', $.proxy(this.handle_keyevent,this)); $(this.code_mirror.getInputField()).attr("spellcheck", "false"); inner_cell.append(input_area); input.append(prompt).append(inner_cell); diff --git a/IPython/html/static/notebook/js/textcell.js b/IPython/html/static/notebook/js/textcell.js index 6fd4bf499..1bcafcf15 100644 --- a/IPython/html/static/notebook/js/textcell.js +++ b/IPython/html/static/notebook/js/textcell.js @@ -340,14 +340,6 @@ define([ this.code_mirror.on('focus', function() { that.unrender(); }); }; - /** - * Trigger autodetection of highlight scheme for current cell - * @method auto_highlight - */ - RawCell.prototype.auto_highlight = function () { - this._auto_highlight(this.class_config.get_sync('highlight_modes')); - }; - /** @method render **/ RawCell.prototype.render = function () { var cont = TextCell.prototype.render.apply(this); @@ -356,6 +348,7 @@ define([ if (text === "") { text = this.placeholder; } this.set_text(text); this.element.removeClass('rendered'); + this.auto_highlight(); } return cont; };