Show More
@@ -86,7 +86,7 b' var IPython = (function (IPython) {' | |||||
86 | if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) { |
|
86 | if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) { | |
87 | // Always ignore shift-enter in CodeMirror as we handle it. |
|
87 | // Always ignore shift-enter in CodeMirror as we handle it. | |
88 | return true; |
|
88 | return true; | |
89 | }else if (event.which === 40 && event.type === 'keypress' && tooltip_wait_time >= 0) { |
|
89 | } else if (event.which === 40 && event.type === 'keypress' && tooltip_wait_time >= 0) { | |
90 | // triger aon keypress (!) otherwise inconsistent event.which depending on plateform |
|
90 | // triger aon keypress (!) otherwise inconsistent event.which depending on plateform | |
91 | // browser and keyboard layout ! |
|
91 | // browser and keyboard layout ! | |
92 | // Pressing '(' , request tooltip, don't forget to reappend it |
|
92 | // Pressing '(' , request tooltip, don't forget to reappend it | |
@@ -499,6 +499,7 b' var IPython = (function (IPython) {' | |||||
499 | select.focus(); |
|
499 | select.focus(); | |
500 | }; |
|
500 | }; | |
501 |
|
501 | |||
|
502 | ||||
502 | CodeCell.prototype.toggle_line_numbers = function () { |
|
503 | CodeCell.prototype.toggle_line_numbers = function () { | |
503 | if (this.code_mirror.getOption('lineNumbers') == false) { |
|
504 | if (this.code_mirror.getOption('lineNumbers') == false) { | |
504 | this.code_mirror.setOption('lineNumbers', true); |
|
505 | this.code_mirror.setOption('lineNumbers', true); | |
@@ -508,15 +509,14 b' var IPython = (function (IPython) {' | |||||
508 | this.code_mirror.refresh(); |
|
509 | this.code_mirror.refresh(); | |
509 | }; |
|
510 | }; | |
510 |
|
511 | |||
|
512 | ||||
511 | CodeCell.prototype.select = function () { |
|
513 | CodeCell.prototype.select = function () { | |
512 | IPython.Cell.prototype.select.apply(this); |
|
514 | IPython.Cell.prototype.select.apply(this); | |
513 | // Todo: this dance is needed because as of CodeMirror 2.12, focus is |
|
515 | // In some cases (inserting a new cell) we need a refresh before and | |
514 | // not causing the cursor to blink if the editor is empty initially. |
|
516 | // after the focus. Not sure why this is the case. | |
515 | // While this seems to fix the issue, this should be fixed |
|
517 | this.code_mirror.refresh(); | |
516 | // in CodeMirror proper. |
|
|||
517 | var s = this.code_mirror.getValue(); |
|
|||
518 | this.code_mirror.focus(); |
|
518 | this.code_mirror.focus(); | |
519 |
|
|
519 | this.code_mirror.refresh(); | |
520 | }; |
|
520 | }; | |
521 |
|
521 | |||
522 |
|
522 |
@@ -516,7 +516,11 b' var IPython = (function (IPython) {' | |||||
516 | source_cell instanceof IPython.MarkdownCell) { |
|
516 | source_cell instanceof IPython.MarkdownCell) { | |
517 | this.insert_code_cell_below(i); |
|
517 | this.insert_code_cell_below(i); | |
518 | var target_cell = this.cells()[i+1]; |
|
518 | var target_cell = this.cells()[i+1]; | |
519 |
|
|
519 | var text = source_cell.get_source(); | |
|
520 | if (text === source_cell.placeholder) { | |||
|
521 | text = ''; | |||
|
522 | } | |||
|
523 | target_cell.set_code(text); | |||
520 | source_element.remove(); |
|
524 | source_element.remove(); | |
521 | target_cell.select(); |
|
525 | target_cell.select(); | |
522 | }; |
|
526 | }; | |
@@ -544,9 +548,11 b' var IPython = (function (IPython) {' | |||||
544 | } |
|
548 | } | |
545 | if (target_cell !== null) { |
|
549 | if (target_cell !== null) { | |
546 | if (text === "") {text = target_cell.placeholder;}; |
|
550 | if (text === "") {text = target_cell.placeholder;}; | |
|
551 | // The edit must come before the set_source. | |||
|
552 | target_cell.edit(); | |||
547 | target_cell.set_source(text); |
|
553 | target_cell.set_source(text); | |
548 | source_element.remove(); |
|
554 | source_element.remove(); | |
549 |
target_cell. |
|
555 | target_cell.select(); | |
550 | } |
|
556 | } | |
551 | this.dirty = true; |
|
557 | this.dirty = true; | |
552 | }; |
|
558 | }; |
@@ -34,7 +34,8 b' var IPython = (function (IPython) {' | |||||
34 | mode: this.code_mirror_mode, |
|
34 | mode: this.code_mirror_mode, | |
35 | theme: 'default', |
|
35 | theme: 'default', | |
36 | value: this.placeholder, |
|
36 | value: this.placeholder, | |
37 | readOnly: this.read_only |
|
37 | readOnly: this.read_only, | |
|
38 | onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this) | |||
38 | }); |
|
39 | }); | |
39 | // The tabindex=-1 makes this div focusable. |
|
40 | // The tabindex=-1 makes this div focusable. | |
40 | var render_area = $('<div/>').addClass('text_cell_render'). |
|
41 | var render_area = $('<div/>').addClass('text_cell_render'). | |
@@ -51,13 +52,27 b' var IPython = (function (IPython) {' | |||||
51 | if (event.which === 13) { |
|
52 | if (event.which === 13) { | |
52 | if (that.rendered) { |
|
53 | if (that.rendered) { | |
53 | that.edit(); |
|
54 | that.edit(); | |
54 |
|
|
55 | return false; | |
55 | } |
|
56 | } | |
56 | } |
|
57 | } | |
57 | }); |
|
58 | }); | |
58 | }; |
|
59 | }; | |
59 |
|
60 | |||
60 |
|
61 | |||
|
62 | TextCell.prototype.handle_codemirror_keyevent = function (editor, event) { | |||
|
63 | // This method gets called in CodeMirror's onKeyDown/onKeyPress | |||
|
64 | // handlers and is used to provide custom key handling. Its return | |||
|
65 | // value is used to determine if CodeMirror should ignore the event: | |||
|
66 | // true = ignore, false = don't ignore. | |||
|
67 | ||||
|
68 | if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) { | |||
|
69 | // Always ignore shift-enter in CodeMirror as we handle it. | |||
|
70 | return true; | |||
|
71 | } | |||
|
72 | return false; | |||
|
73 | }; | |||
|
74 | ||||
|
75 | ||||
61 | TextCell.prototype.select = function () { |
|
76 | TextCell.prototype.select = function () { | |
62 | IPython.Cell.prototype.select.apply(this); |
|
77 | IPython.Cell.prototype.select.apply(this); | |
63 | var output = this.element.find("div.text_cell_render"); |
|
78 | var output = this.element.find("div.text_cell_render"); | |
@@ -73,14 +88,16 b' var IPython = (function (IPython) {' | |||||
73 |
|
88 | |||
74 |
|
89 | |||
75 | TextCell.prototype.edit = function () { |
|
90 | TextCell.prototype.edit = function () { | |
|
91 | var that = this; | |||
76 | if ( this.read_only ) return; |
|
92 | if ( this.read_only ) return; | |
77 | if (this.rendered === true) { |
|
93 | if (this.rendered === true) { | |
78 | var text_cell = this.element; |
|
94 | var text_cell = this.element; | |
79 | var output = text_cell.find("div.text_cell_render"); |
|
95 | var output = text_cell.find("div.text_cell_render"); | |
80 | output.hide(); |
|
96 | output.hide(); | |
81 | text_cell.find('div.text_cell_input').show(); |
|
97 | text_cell.find('div.text_cell_input').show(); | |
|
98 | that.code_mirror.refresh(); | |||
82 | this.code_mirror.focus(); |
|
99 | this.code_mirror.focus(); | |
83 |
th |
|
100 | that.code_mirror.refresh(); | |
84 | this.rendered = false; |
|
101 | this.rendered = false; | |
85 | if (this.get_source() === this.placeholder) { |
|
102 | if (this.get_source() === this.placeholder) { | |
86 | this.set_source(''); |
|
103 | this.set_source(''); |
General Comments 0
You need to be logged in to leave comments.
Login now