Show More
@@ -26,8 +26,16 b' var IPython = (function (IPython) {' | |||
|
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 b' 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. |
@@ -32,14 +32,29 b' var IPython = (function (IPython) {' | |||
|
32 | 32 | * |
|
33 | 33 | * @constructor |
|
34 | 34 | * @param {Object|null} kernel |
|
35 | * @param {object|undefined} [options] | |
|
36 | * @param [options.cm_config] {object} config to pass to CodeMirror | |
|
35 | 37 | */ |
|
36 | var CodeCell = function (kernel) { | |
|
38 | var CodeCell = function (kernel, options) { | |
|
37 | 39 | this.kernel = kernel || null; |
|
38 | 40 | this.code_mirror = null; |
|
39 | 41 | this.input_prompt_number = null; |
|
40 | 42 | this.collapsed = false; |
|
41 | 43 | this.default_mode = 'python'; |
|
42 | IPython.Cell.apply(this, arguments); | |
|
44 | ||
|
45 | ||
|
46 | var cm_overwrite_options = { | |
|
47 | extraKeys: {"Tab": "indentMore","Shift-Tab" : "indentLess",'Backspace':"delSpaceToPrevTabStop"}, | |
|
48 | onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this) | |
|
49 | }; | |
|
50 | ||
|
51 | var arg_cm_options = options.cm_options || {}; | |
|
52 | var cm_config = $.extend({},CodeCell.cm_default, arg_cm_options, cm_overwrite_options); | |
|
53 | ||
|
54 | var options = {}; | |
|
55 | options.cm_config = cm_config; | |
|
56 | ||
|
57 | IPython.Cell.apply(this,[options]); | |
|
43 | 58 | |
|
44 | 59 | var that = this; |
|
45 | 60 | this.element.focusout( |
@@ -47,6 +62,13 b' var IPython = (function (IPython) {' | |||
|
47 | 62 | ); |
|
48 | 63 | }; |
|
49 | 64 | |
|
65 | CodeCell.cm_default = { | |
|
66 | mode: 'python', | |
|
67 | theme: 'ipython', | |
|
68 | matchBrackets: true | |
|
69 | }; | |
|
70 | ||
|
71 | ||
|
50 | 72 | CodeCell.prototype = new IPython.Cell(); |
|
51 | 73 | |
|
52 | 74 | /** |
@@ -70,15 +92,7 b' var IPython = (function (IPython) {' | |||
|
70 | 92 | input.append($('<div/>').addClass('prompt input_prompt')); |
|
71 | 93 | vbox.append(this.celltoolbar.element); |
|
72 | 94 | var input_area = $('<div/>').addClass('input_area'); |
|
73 |
this.code_mirror = CodeMirror(input_area.get(0), |
|
|
74 | indentUnit : 4, | |
|
75 | mode: 'python', | |
|
76 | theme: 'ipython', | |
|
77 | readOnly: this.read_only, | |
|
78 | extraKeys: {"Tab": "indentMore","Shift-Tab" : "indentLess",'Backspace':"delSpaceToPrevTabStop"}, | |
|
79 | onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this), | |
|
80 | matchBrackets: true | |
|
81 | }); | |
|
95 | this.code_mirror = CodeMirror(input_area.get(0), this.cm_config); | |
|
82 | 96 | vbox.append(input_area); |
|
83 | 97 | input.append(vbox); |
|
84 | 98 | var output = $('<div></div>'); |
@@ -26,14 +26,38 b' 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 b' 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