Show More
@@ -83,6 +83,10 b' span.section_row_buttons > button {' | |||||
83 | float: right; |
|
83 | float: right; | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
|
86 | #autoindent_span { | |||
|
87 | float: right; | |||
|
88 | } | |||
|
89 | ||||
86 | .checkbox_label { |
|
90 | .checkbox_label { | |
87 | font-size: 85%; |
|
91 | font-size: 85%; | |
88 | float: right; |
|
92 | float: right; |
@@ -68,6 +68,17 b' var IPython = (function (IPython) {' | |||||
68 | }; |
|
68 | }; | |
69 |
|
69 | |||
70 |
|
70 | |||
|
71 | Cell.prototype.set_autoindent = function (state) { | |||
|
72 | if (state) { | |||
|
73 | this.code_mirror.setOption('tabMode', 'indent'); | |||
|
74 | this.code_mirror.setOption('enterMode', 'indent'); | |||
|
75 | } else { | |||
|
76 | this.code_mirror.setOption('tabMode', 'shift'); | |||
|
77 | this.code_mirror.setOption('enterMode', 'flat'); | |||
|
78 | } | |||
|
79 | }; | |||
|
80 | ||||
|
81 | ||||
71 | // Subclasses must implement create_element. |
|
82 | // Subclasses must implement create_element. | |
72 | Cell.prototype.create_element = function () {}; |
|
83 | Cell.prototype.create_element = function () {}; | |
73 |
|
84 |
@@ -48,8 +48,7 b' var IPython = (function (IPython) {' | |||||
48 | if (event.keyCode === 13 && event.shiftKey) { |
|
48 | if (event.keyCode === 13 && event.shiftKey) { | |
49 | // Always ignore shift-enter in CodeMirror as we handle it. |
|
49 | // Always ignore shift-enter in CodeMirror as we handle it. | |
50 | return true; |
|
50 | return true; | |
51 | // } else if (event.keyCode == 32 && (event.ctrlKey || event.metaKey) && !event.altKey) { |
|
51 | } else if (event.keyCode === 9) { | |
52 | } else if (event.keyCode == 9) { |
|
|||
53 | var cur = editor.getCursor(); |
|
52 | var cur = editor.getCursor(); | |
54 | var pre_cursor = editor.getRange({line:cur.line,ch:0},cur).trim(); |
|
53 | var pre_cursor = editor.getRange({line:cur.line,ch:0},cur).trim(); | |
55 | if (pre_cursor === "") { |
|
54 | if (pre_cursor === "") { | |
@@ -65,6 +64,21 b' var IPython = (function (IPython) {' | |||||
65 | IPython.notebook.complete_cell(this, line, cur.ch); |
|
64 | IPython.notebook.complete_cell(this, line, cur.ch); | |
66 | return true; |
|
65 | return true; | |
67 | } |
|
66 | } | |
|
67 | } else if (event.keyCode === 8) { | |||
|
68 | // If backspace and the line ends with 4 spaces, remove them. | |||
|
69 | var cur = editor.getCursor(); | |||
|
70 | var line = editor.getLine(cur.line); | |||
|
71 | var ending = line.slice(-4); | |||
|
72 | if (ending === ' ') { | |||
|
73 | editor.replaceRange('', | |||
|
74 | {line: cur.line, ch: cur.ch-4}, | |||
|
75 | {line: cur.line, ch: cur.ch} | |||
|
76 | ); | |||
|
77 | event.stop(); | |||
|
78 | return true; | |||
|
79 | } else { | |||
|
80 | return false; | |||
|
81 | }; | |||
68 | } else { |
|
82 | } else { | |
69 | if (this.is_completing && this.completion_cursor !== editor.getCursor()) { |
|
83 | if (this.is_completing && this.completion_cursor !== editor.getCursor()) { | |
70 | this.is_completing = false; |
|
84 | this.is_completing = false; |
@@ -447,6 +447,14 b' var IPython = (function (IPython) {' | |||||
447 | }; |
|
447 | }; | |
448 |
|
448 | |||
449 |
|
449 | |||
|
450 | Notebook.prototype.set_autoindent = function (state) { | |||
|
451 | var cells = this.cells(); | |||
|
452 | len = cells.length; | |||
|
453 | for (var i=0; i<len; i++) { | |||
|
454 | cells[i].set_autoindent(state) | |||
|
455 | }; | |||
|
456 | }; | |||
|
457 | ||||
450 | // Kernel related things |
|
458 | // Kernel related things | |
451 |
|
459 | |||
452 | Notebook.prototype.start_kernel = function () { |
|
460 | Notebook.prototype.start_kernel = function () { |
@@ -167,6 +167,10 b' var IPython = (function (IPython) {' | |||||
167 | this.content.find('#run_all_cells').click(function () { |
|
167 | this.content.find('#run_all_cells').click(function () { | |
168 | IPython.notebook.execute_all_cells(); |
|
168 | IPython.notebook.execute_all_cells(); | |
169 | }); |
|
169 | }); | |
|
170 | this.content.find('#autoindent').change(function () { | |||
|
171 | var state = $('#autoindent').prop('checked'); | |||
|
172 | IPython.notebook.set_autoindent(state); | |||
|
173 | }); | |||
170 | }; |
|
174 | }; | |
171 |
|
175 | |||
172 |
|
176 |
@@ -119,6 +119,12 b'' | |||||
119 | </span> |
|
119 | </span> | |
120 | <span class="button_label">Run</span> |
|
120 | <span class="button_label">Run</span> | |
121 | </div> |
|
121 | </div> | |
|
122 | <div class="section_row"> | |||
|
123 | <span id="autoindent_span"> | |||
|
124 | <input type="checkbox" id="autoindent"></input> | |||
|
125 | </span> | |||
|
126 | <span class="checkbox_label">Autoindent:</span> | |||
|
127 | </div> | |||
122 | </div> |
|
128 | </div> | |
123 | </div> |
|
129 | </div> | |
124 |
|
130 |
General Comments 0
You need to be logged in to leave comments.
Login now