##// END OF EJS Templates
Merge pull request #2894 from Carreau/cm-configurable...
Bussonnier Matthias -
r9695:98972ec3 merge
parent child Browse files
Show More
@@ -22,12 +22,20 var IPython = (function (IPython) {
22 22 /**
23 23 * The Base `Cell` class from which to inherit
24 24 * @class Cell
25 */
25 **/
26 26
27 27 /*
28 28 * @constructor
29 *
30 * @param {object|undefined} [options]
31 * @param [options.cm_config] {object} config to pass to CodeMirror, will extend default parameters
29 32 */
30 var Cell = function () {
33 var Cell = function (options) {
34
35 options = options || {};
36 // superclass default overwrite our default
37 this.cm_config = $.extend({},Cell.cm_default,options.cm_config);
38
31 39 this.placeholder = this.placeholder || '';
32 40 this.read_only = false;
33 41 this.selected = false;
@@ -43,6 +51,11 var IPython = (function (IPython) {
43 51 this.cell_id = utils.uuid();
44 52 };
45 53
54 Cell.cm_default = {
55 indentUnit : 4,
56 readOnly: this.read_only,
57 };
58
46 59
47 60 /**
48 61 * Empty. Subclasses must implement create_element.
@@ -240,7 +253,7 var IPython = (function (IPython) {
240 253 };
241 254
242 255 /**
243 * force codemirror highlight mode
256 * Force codemirror highlight mode
244 257 * @method force_highlight
245 258 * @param {object} - CodeMirror mode
246 259 **/
@@ -58,14 +58,30 var IPython = (function (IPython) {
58 58 *
59 59 * @constructor
60 60 * @param {Object|null} kernel
61 * @param {object|undefined} [options]
62 * @param [options.cm_config] {object} config to pass to CodeMirror
61 63 */
62 var CodeCell = function (kernel) {
64 var CodeCell = function (kernel, options) {
65 var options = options || {}
63 66 this.kernel = kernel || null;
64 67 this.code_mirror = null;
65 68 this.input_prompt_number = null;
66 69 this.collapsed = false;
67 70 this.default_mode = 'python';
68 IPython.Cell.apply(this, arguments);
71
72
73 var cm_overwrite_options = {
74 extraKeys: {"Tab": "indentMore","Shift-Tab" : "indentLess",'Backspace':"delSpaceToPrevTabStop"},
75 onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this)
76 };
77
78 var arg_cm_options = options.cm_options || {};
79 var cm_config = $.extend({},CodeCell.cm_default, arg_cm_options, cm_overwrite_options);
80
81 var options = {};
82 options.cm_config = cm_config;
83
84 IPython.Cell.apply(this,[options]);
69 85
70 86 var that = this;
71 87 this.element.focusout(
@@ -73,6 +89,13 var IPython = (function (IPython) {
73 89 );
74 90 };
75 91
92 CodeCell.cm_default = {
93 mode: 'python',
94 theme: 'ipython',
95 matchBrackets: true
96 };
97
98
76 99 CodeCell.prototype = new IPython.Cell();
77 100
78 101 /**
@@ -96,15 +119,7 var IPython = (function (IPython) {
96 119 input.append($('<div/>').addClass('prompt input_prompt'));
97 120 vbox.append(this.celltoolbar.element);
98 121 var input_area = $('<div/>').addClass('input_area');
99 this.code_mirror = CodeMirror(input_area.get(0), {
100 indentUnit : 4,
101 mode: 'python',
102 theme: 'ipython',
103 readOnly: this.read_only,
104 extraKeys: {"Tab": "indentMore","Shift-Tab" : "indentLess",'Backspace':"delSpaceToPrevTabStop"},
105 onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this),
106 matchBrackets: true
107 });
122 this.code_mirror = CodeMirror(input_area.get(0), this.cm_config);
108 123 vbox.append(input_area);
109 124 input.append(vbox);
110 125 var output = $('<div></div>');
@@ -26,14 +26,38 var IPython = (function (IPython) {
26 26 * @class TextCell
27 27 * @constructor TextCell
28 28 * @extend Ipython.Cell
29 * @param {object|undefined} [options]
30 * @param [options.cm_config] {object} config to pass to CodeMirror, will extend/overwrite default config
29 31 */
30 var TextCell = function () {
32 var TextCell = function (options) {
31 33 this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed';
32 IPython.Cell.apply(this, arguments);
34 var options = options || {};
35
36 var cm_overwrite_options = {
37 extraKeys: {"Tab": "indentMore","Shift-Tab" : "indentLess"},
38 onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this)
39 };
40
41 var arg_cm_options = options.cm_options || {};
42 var cm_config = $.extend({},TextCell.cm_default, arg_cm_options, cm_overwrite_options);
43
44 var options = {};
45 options.cm_config = cm_config;
46
47
48 IPython.Cell.apply(this, [options]);
33 49 this.rendered = false;
34 50 this.cell_type = this.cell_type || 'text';
35 51 };
36 52
53 TextCell.cm_default = {
54 mode: this.code_mirror_mode,
55 theme: 'default',
56 value: this.placeholder,
57 lineWrapping : true,
58 }
59
60
37 61 TextCell.prototype = new IPython.Cell();
38 62
39 63 /**
@@ -50,16 +74,7 var IPython = (function (IPython) {
50 74 cell.append(this.celltoolbar.element);
51 75
52 76 var input_area = $('<div/>').addClass('text_cell_input border-box-sizing');
53 this.code_mirror = CodeMirror(input_area.get(0), {
54 indentUnit : 4,
55 mode: this.code_mirror_mode,
56 theme: 'default',
57 value: this.placeholder,
58 readOnly: this.read_only,
59 lineWrapping : true,
60 extraKeys: {"Tab": "indentMore","Shift-Tab" : "indentLess"},
61 onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this)
62 });
77 this.code_mirror = CodeMirror(input_area.get(0), this.cm_config);
63 78 // The tabindex=-1 makes this div focusable.
64 79 var render_area = $('<div/>').addClass('text_cell_render border-box-sizing').
65 80 addClass('rendered_html').attr('tabindex','-1');
General Comments 0
You need to be logged in to leave comments. Login now