Show More
@@ -39,18 +39,28 b' var IPython = (function (IPython) {' | |||||
39 | this.placeholder = options.placeholder || ''; |
|
39 | this.placeholder = options.placeholder || ''; | |
40 | this.read_only = options.cm_config.readOnly; |
|
40 | this.read_only = options.cm_config.readOnly; | |
41 | this.selected = false; |
|
41 | this.selected = false; | |
42 | this.element = null; |
|
|||
43 | this.metadata = {}; |
|
42 | this.metadata = {}; | |
44 | // load this from metadata later ? |
|
43 | // load this from metadata later ? | |
45 | this.user_highlight = 'auto'; |
|
44 | this.user_highlight = 'auto'; | |
46 | this.cm_config = options.cm_config; |
|
45 | this.cm_config = options.cm_config; | |
|
46 | this.cell_id = utils.uuid(); | |||
|
47 | this._options = options; | |||
|
48 | ||||
|
49 | // For JS VM engines optimisation, attributes should be all set (even | |||
|
50 | // to null) in the constructor, and if possible, if different subclass | |||
|
51 | // have new attributes with same name, they should be created in the | |||
|
52 | // same order. Easiest is to create and set to null in parent class. | |||
|
53 | ||||
|
54 | this.element = null; | |||
|
55 | this.cell_type = null; | |||
|
56 | this.code_mirror = null; | |||
|
57 | ||||
|
58 | ||||
47 | this.create_element(); |
|
59 | this.create_element(); | |
48 | if (this.element !== null) { |
|
60 | if (this.element !== null) { | |
49 | this.element.data("cell", this); |
|
61 | this.element.data("cell", this); | |
50 | this.bind_events(); |
|
62 | this.bind_events(); | |
51 | } |
|
63 | } | |
52 | this.cell_id = utils.uuid(); |
|
|||
53 | this._options = options; |
|
|||
54 | }; |
|
64 | }; | |
55 |
|
65 | |||
56 | Cell.options_default = { |
|
66 | Cell.options_default = { | |
@@ -295,6 +305,7 b' var IPython = (function (IPython) {' | |||||
295 | this.code_mirror.setOption('mode', mode); |
|
305 | this.code_mirror.setOption('mode', mode); | |
296 | return; |
|
306 | return; | |
297 | } |
|
307 | } | |
|
308 | var current_mode = this.code_mirror.getOption('mode', mode); | |||
298 | var first_line = this.code_mirror.getLine(0); |
|
309 | var first_line = this.code_mirror.getLine(0); | |
299 | // loop on every pairs |
|
310 | // loop on every pairs | |
300 | for( var mode in modes) { |
|
311 | for( var mode in modes) { | |
@@ -303,6 +314,9 b' var IPython = (function (IPython) {' | |||||
303 | for(var reg in regs ) { |
|
314 | for(var reg in regs ) { | |
304 | // here we handle non magic_modes |
|
315 | // here we handle non magic_modes | |
305 | if(first_line.match(regs[reg]) != null) { |
|
316 | if(first_line.match(regs[reg]) != null) { | |
|
317 | if(current_mode == mode){ | |||
|
318 | return; | |||
|
319 | } | |||
306 | if (mode.search('magic_') != 0) { |
|
320 | if (mode.search('magic_') != 0) { | |
307 | this.code_mirror.setOption('mode', mode); |
|
321 | this.code_mirror.setOption('mode', mode); | |
308 | CodeMirror.autoLoadMode(this.code_mirror, mode); |
|
322 | CodeMirror.autoLoadMode(this.code_mirror, mode); | |
@@ -312,6 +326,9 b' var IPython = (function (IPython) {' | |||||
312 | var close = modes[mode]['close']|| "%%end"; |
|
326 | var close = modes[mode]['close']|| "%%end"; | |
313 | var mmode = mode; |
|
327 | var mmode = mode; | |
314 | mode = mmode.substr(6); |
|
328 | mode = mmode.substr(6); | |
|
329 | if(current_mode == mode){ | |||
|
330 | return; | |||
|
331 | } | |||
315 | CodeMirror.autoLoadMode(this.code_mirror, mode); |
|
332 | CodeMirror.autoLoadMode(this.code_mirror, mode); | |
316 | // create on the fly a mode that swhitch between |
|
333 | // create on the fly a mode that swhitch between | |
317 | // plain/text and smth else otherwise `%%` is |
|
334 | // plain/text and smth else otherwise `%%` is | |
@@ -339,6 +356,9 b' var IPython = (function (IPython) {' | |||||
339 | } catch(e) { |
|
356 | } catch(e) { | |
340 | default_mode = 'text/plain'; |
|
357 | default_mode = 'text/plain'; | |
341 | } |
|
358 | } | |
|
359 | if( current_mode === default_mode){ | |||
|
360 | return | |||
|
361 | } | |||
342 | this.code_mirror.setOption('mode', default_mode); |
|
362 | this.code_mirror.setOption('mode', default_mode); | |
343 | }; |
|
363 | }; | |
344 |
|
364 |
@@ -62,11 +62,17 b' var IPython = (function (IPython) {' | |||||
62 | */ |
|
62 | */ | |
63 | var CodeCell = function (kernel, options) { |
|
63 | var CodeCell = function (kernel, options) { | |
64 | this.kernel = kernel || null; |
|
64 | this.kernel = kernel || null; | |
65 | this.code_mirror = null; |
|
|||
66 | this.input_prompt_number = null; |
|
|||
67 | this.collapsed = false; |
|
65 | this.collapsed = false; | |
68 | this.cell_type = "code"; |
|
66 | this.cell_type = "code"; | |
69 |
|
67 | |||
|
68 | // create all attributed in constructor function | |||
|
69 | // even if null for V8 VM optimisation | |||
|
70 | this.input_prompt_number = null; | |||
|
71 | this.celltoolbar = null; | |||
|
72 | this.output_area = null; | |||
|
73 | this.last_msg_id = null; | |||
|
74 | this.completer = null; | |||
|
75 | ||||
70 |
|
76 | |||
71 | var cm_overwrite_options = { |
|
77 | var cm_overwrite_options = { | |
72 | onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this) |
|
78 | onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this) | |
@@ -129,13 +135,7 b' var IPython = (function (IPython) {' | |||||
129 | cell.append(input).append(output); |
|
135 | cell.append(input).append(output); | |
130 | this.element = cell; |
|
136 | this.element = cell; | |
131 | this.output_area = new IPython.OutputArea(output, true); |
|
137 | this.output_area = new IPython.OutputArea(output, true); | |
132 |
|
138 | this.completer = new IPython.Completer(this); | ||
133 | // construct a completer only if class exist |
|
|||
134 | // otherwise no print view |
|
|||
135 | if (IPython.Completer !== undefined) |
|
|||
136 | { |
|
|||
137 | this.completer = new IPython.Completer(this); |
|
|||
138 | } |
|
|||
139 | }; |
|
139 | }; | |
140 |
|
140 | |||
141 | /** |
|
141 | /** | |
@@ -202,8 +202,10 b' var IPython = (function (IPython) {' | |||||
202 | return true; |
|
202 | return true; | |
203 | } else if (event.keyCode === key.TAB && event.type == 'keydown') { |
|
203 | } else if (event.keyCode === key.TAB && event.type == 'keydown') { | |
204 | // Tab completion. |
|
204 | // Tab completion. | |
205 | //Do not trim here because of tooltip |
|
205 | IPython.tooltip.remove_and_cancel_tooltip(); | |
206 |
if (editor.somethingSelected()) { |
|
206 | if (editor.somethingSelected()) { | |
|
207 | return false; | |||
|
208 | } | |||
207 | var pre_cursor = editor.getRange({line:cur.line,ch:0},cur); |
|
209 | var pre_cursor = editor.getRange({line:cur.line,ch:0},cur); | |
208 | if (pre_cursor.trim() === "") { |
|
210 | if (pre_cursor.trim() === "") { | |
209 | // Don't autocomplete if the part of the line before the cursor |
|
211 | // Don't autocomplete if the part of the line before the cursor | |
@@ -443,7 +445,8 b' var IPython = (function (IPython) {' | |||||
443 | var data = IPython.Cell.prototype.toJSON.apply(this); |
|
445 | var data = IPython.Cell.prototype.toJSON.apply(this); | |
444 | data.input = this.get_text(); |
|
446 | data.input = this.get_text(); | |
445 | data.cell_type = 'code'; |
|
447 | data.cell_type = 'code'; | |
446 | if (this.input_prompt_number) { |
|
448 | // is finite protect against undefined and '*' value | |
|
449 | if (isFinite(this.input_prompt_number)) { | |||
447 | data.prompt_number = this.input_prompt_number; |
|
450 | data.prompt_number = this.input_prompt_number; | |
448 | } |
|
451 | } | |
449 | var outputs = this.output_area.toJSON(); |
|
452 | var outputs = this.output_area.toJSON(); |
@@ -1588,7 +1588,7 b' var IPython = (function (IPython) {' | |||||
1588 | cell_data.cell_type = 'raw'; |
|
1588 | cell_data.cell_type = 'raw'; | |
1589 | } |
|
1589 | } | |
1590 |
|
1590 | |||
1591 |
new_cell = this.insert_cell_ |
|
1591 | new_cell = this.insert_cell_at_bottom(cell_data.cell_type); | |
1592 | new_cell.fromJSON(cell_data); |
|
1592 | new_cell.fromJSON(cell_data); | |
1593 | }; |
|
1593 | }; | |
1594 | }; |
|
1594 | }; |
@@ -576,12 +576,13 b' var IPython = (function (IPython) {' | |||||
576 |
|
576 | |||
577 | OutputArea.prototype.append_png = function (png, md, element) { |
|
577 | OutputArea.prototype.append_png = function (png, md, element) { | |
578 | var toinsert = this.create_output_subarea(md, "output_png"); |
|
578 | var toinsert = this.create_output_subarea(md, "output_png"); | |
579 | var img = $("<img/>").attr('src','data:image/png;base64,'+png); |
|
579 | var img = $("<img/>"); | |
|
580 | img[0].setAttribute('src','data:image/png;base64,'+png); | |||
580 | if (md['height']) { |
|
581 | if (md['height']) { | |
581 |
img. |
|
582 | img[0].setAttribute('height', md['height']); | |
582 | } |
|
583 | } | |
583 | if (md['width']) { |
|
584 | if (md['width']) { | |
584 |
img. |
|
585 | img[0].setAttribute('width', md['width']); | |
585 | } |
|
586 | } | |
586 | this._dblclick_to_reset_size(img); |
|
587 | this._dblclick_to_reset_size(img); | |
587 | toinsert.append(img); |
|
588 | toinsert.append(img); |
General Comments 0
You need to be logged in to leave comments.
Login now