Show More
@@ -123,7 +123,12 b' var IPython = (function (IPython) {' | |||||
123 | this.code_mirror.on("change", function(cm, change) { |
|
123 | this.code_mirror.on("change", function(cm, change) { | |
124 | $([IPython.events]).trigger("set_dirty.Notebook", {value: true}); |
|
124 | $([IPython.events]).trigger("set_dirty.Notebook", {value: true}); | |
125 | }); |
|
125 | }); | |
126 | } |
|
126 | }; | |
|
127 | if (this.code_mirror) { | |||
|
128 | this.code_mirror.on('focus', function(cm, change) { | |||
|
129 | $([IPython.events]).trigger('edit_mode.Cell', {cell: that}); | |||
|
130 | }); | |||
|
131 | }; | |||
127 | }; |
|
132 | }; | |
128 |
|
133 | |||
129 | /** |
|
134 | /** | |
@@ -143,12 +148,14 b' var IPython = (function (IPython) {' | |||||
143 | * @return is the action being taken |
|
148 | * @return is the action being taken | |
144 | */ |
|
149 | */ | |
145 | Cell.prototype.select = function () { |
|
150 | Cell.prototype.select = function () { | |
|
151 | console.log('Cell.select'); | |||
146 | if (!this.selected) { |
|
152 | if (!this.selected) { | |
147 | this.element.addClass('selected'); |
|
153 | this.element.addClass('selected'); | |
148 | this.element.removeClass('unselected'); |
|
154 | this.element.removeClass('unselected'); | |
149 | this.selected = true; |
|
155 | this.selected = true; | |
150 | return true; |
|
156 | return true; | |
151 | } else { |
|
157 | } else { | |
|
158 | console.log('WARNING: select'); | |||
152 | return false; |
|
159 | return false; | |
153 | }; |
|
160 | }; | |
154 | }; |
|
161 | }; | |
@@ -159,12 +166,14 b' var IPython = (function (IPython) {' | |||||
159 | * @return is the action being taken |
|
166 | * @return is the action being taken | |
160 | */ |
|
167 | */ | |
161 | Cell.prototype.unselect = function () { |
|
168 | Cell.prototype.unselect = function () { | |
|
169 | console.log('Cell.unselect'); | |||
162 | if (this.selected) { |
|
170 | if (this.selected) { | |
163 | this.element.addClass('unselected'); |
|
171 | this.element.addClass('unselected'); | |
164 | this.element.removeClass('selected'); |
|
172 | this.element.removeClass('selected'); | |
165 | this.selected = false; |
|
173 | this.selected = false; | |
166 | return true; |
|
174 | return true; | |
167 | } else { |
|
175 | } else { | |
|
176 | console.log('WARNING: unselect'); | |||
168 | return false; |
|
177 | return false; | |
169 | }; |
|
178 | }; | |
170 | }; |
|
179 | }; | |
@@ -175,12 +184,14 b' var IPython = (function (IPython) {' | |||||
175 | * @return is the action being taken |
|
184 | * @return is the action being taken | |
176 | */ |
|
185 | */ | |
177 | Cell.prototype.render = function () { |
|
186 | Cell.prototype.render = function () { | |
|
187 | console.log('Cell.render'); | |||
178 | if (!this.rendered) { |
|
188 | if (!this.rendered) { | |
179 | this.element.addClass('rendered'); |
|
189 | this.element.addClass('rendered'); | |
180 | this.element.removeClass('unrendered'); |
|
190 | this.element.removeClass('unrendered'); | |
181 | this.rendered = true; |
|
191 | this.rendered = true; | |
182 | return true; |
|
192 | return true; | |
183 | } else { |
|
193 | } else { | |
|
194 | console.log('WARNING: render'); | |||
184 | return false; |
|
195 | return false; | |
185 | }; |
|
196 | }; | |
186 | }; |
|
197 | }; | |
@@ -191,12 +202,14 b' var IPython = (function (IPython) {' | |||||
191 | * @return is the action being taken |
|
202 | * @return is the action being taken | |
192 | */ |
|
203 | */ | |
193 | Cell.prototype.unrender = function () { |
|
204 | Cell.prototype.unrender = function () { | |
|
205 | console.log('Cell.unrender'); | |||
194 | if (this.rendered) { |
|
206 | if (this.rendered) { | |
195 | this.element.addClass('unrendered'); |
|
207 | this.element.addClass('unrendered'); | |
196 | this.element.removeClass('rendered'); |
|
208 | this.element.removeClass('rendered'); | |
197 | this.rendered = false; |
|
209 | this.rendered = false; | |
198 | return true; |
|
210 | return true; | |
199 | } else { |
|
211 | } else { | |
|
212 | console.log('WARNING: unrender'); | |||
200 | return false; |
|
213 | return false; | |
201 | }; |
|
214 | }; | |
202 | }; |
|
215 | }; | |
@@ -207,12 +220,14 b' var IPython = (function (IPython) {' | |||||
207 | * @return is the action being taken |
|
220 | * @return is the action being taken | |
208 | */ |
|
221 | */ | |
209 | Cell.prototype.command_mode = function () { |
|
222 | Cell.prototype.command_mode = function () { | |
|
223 | console.log('Cell.command_mode:', this.mode); | |||
210 | if (this.mode !== 'command') { |
|
224 | if (this.mode !== 'command') { | |
211 | this.element.addClass('command_mode'); |
|
225 | this.element.addClass('command_mode'); | |
212 | this.element.removeClass('edit_mode'); |
|
226 | this.element.removeClass('edit_mode'); | |
213 | this.mode = 'command'; |
|
227 | this.mode = 'command'; | |
214 | return true; |
|
228 | return true; | |
215 | } else { |
|
229 | } else { | |
|
230 | console.log('WARNING: command_mode'); | |||
216 | return false; |
|
231 | return false; | |
217 | }; |
|
232 | }; | |
218 | }; |
|
233 | }; | |
@@ -223,12 +238,14 b' var IPython = (function (IPython) {' | |||||
223 | * @return is the action being taken |
|
238 | * @return is the action being taken | |
224 | */ |
|
239 | */ | |
225 | Cell.prototype.edit_mode = function () { |
|
240 | Cell.prototype.edit_mode = function () { | |
|
241 | console.log('Cell.edit_mode:', this.mode); | |||
226 | if (this.mode !== 'edit') { |
|
242 | if (this.mode !== 'edit') { | |
227 | this.element.addClass('edit_mode'); |
|
243 | this.element.addClass('edit_mode'); | |
228 | this.element.removeClass('command_mode'); |
|
244 | this.element.removeClass('command_mode'); | |
229 | this.mode = 'edit'; |
|
245 | this.mode = 'edit'; | |
230 | return true; |
|
246 | return true; | |
231 | } else { |
|
247 | } else { | |
|
248 | console.log('WARNING: edit_mode'); | |||
232 | return false; |
|
249 | return false; | |
233 | }; |
|
250 | }; | |
234 | } |
|
251 | } | |
@@ -246,26 +263,11 b' var IPython = (function (IPython) {' | |||||
246 | * @method focus_editor |
|
263 | * @method focus_editor | |
247 | */ |
|
264 | */ | |
248 | Cell.prototype.focus_editor = function () { |
|
265 | Cell.prototype.focus_editor = function () { | |
249 |
this |
|
266 | this.refresh(); | |
250 | this.code_mirror.focus(); |
|
267 | this.code_mirror.focus(); | |
251 | } |
|
268 | } | |
252 |
|
269 | |||
253 | /** |
|
270 | /** | |
254 | * should be overritten by subclass |
|
|||
255 | * @method get_text |
|
|||
256 | */ |
|
|||
257 | Cell.prototype.get_text = function () { |
|
|||
258 | }; |
|
|||
259 |
|
||||
260 | /** |
|
|||
261 | * should be overritten by subclass |
|
|||
262 | * @method set_text |
|
|||
263 | * @param {string} text |
|
|||
264 | */ |
|
|||
265 | Cell.prototype.set_text = function (text) { |
|
|||
266 | }; |
|
|||
267 |
|
||||
268 | /** |
|
|||
269 | * Refresh codemirror instance |
|
271 | * Refresh codemirror instance | |
270 | * @method refresh |
|
272 | * @method refresh | |
271 | */ |
|
273 | */ | |
@@ -273,20 +275,19 b' var IPython = (function (IPython) {' | |||||
273 | this.code_mirror.refresh(); |
|
275 | this.code_mirror.refresh(); | |
274 | }; |
|
276 | }; | |
275 |
|
277 | |||
276 |
|
||||
277 | /** |
|
278 | /** | |
278 | * should be overritten by subclass |
|
279 | * should be overritten by subclass | |
279 |
* @method |
|
280 | * @method get_text | |
280 |
* |
|
281 | */ | |
281 |
Cell.prototype. |
|
282 | Cell.prototype.get_text = function () { | |
282 | }; |
|
283 | }; | |
283 |
|
284 | |||
284 |
|
||||
285 | /** |
|
285 | /** | |
286 | * should be overritten by subclass |
|
286 | * should be overritten by subclass | |
287 |
* @method |
|
287 | * @method set_text | |
288 | **/ |
|
288 | * @param {string} text | |
289 | Cell.prototype.render = function () { |
|
289 | */ | |
|
290 | Cell.prototype.set_text = function (text) { | |||
290 | }; |
|
291 | }; | |
291 |
|
292 | |||
292 | /** |
|
293 | /** |
@@ -139,6 +139,16 b' var IPython = (function (IPython) {' | |||||
139 | this.completer = new IPython.Completer(this); |
|
139 | this.completer = new IPython.Completer(this); | |
140 | }; |
|
140 | }; | |
141 |
|
141 | |||
|
142 | /** @method bind_events */ | |||
|
143 | CodeCell.prototype.bind_events = function () { | |||
|
144 | IPython.Cell.prototype.bind_events.apply(this); | |||
|
145 | var that = this; | |||
|
146 | ||||
|
147 | this.element.focusout( | |||
|
148 | function() { that.auto_highlight(); } | |||
|
149 | ); | |||
|
150 | }; | |||
|
151 | ||||
142 | /** |
|
152 | /** | |
143 | * This method gets called in CodeMirror's onKeyDown/onKeyPress |
|
153 | * This method gets called in CodeMirror's onKeyDown/onKeyPress | |
144 | * handlers and is used to provide custom key handling. Its return |
|
154 | * handlers and is used to provide custom key handling. Its return | |
@@ -308,44 +318,43 b' var IPython = (function (IPython) {' | |||||
308 | // Basic cell manipulation. |
|
318 | // Basic cell manipulation. | |
309 |
|
319 | |||
310 | CodeCell.prototype.select = function () { |
|
320 | CodeCell.prototype.select = function () { | |
311 |
var cont |
|
321 | var cont = IPython.Cell.prototype.select.apply(this); | |
312 | if (continue) { |
|
322 | console.log('CodeCell.select', cont); | |
|
323 | if (cont) { | |||
313 | this.code_mirror.refresh(); |
|
324 | this.code_mirror.refresh(); | |
314 | this.auto_highlight(); |
|
325 | this.auto_highlight(); | |
315 | }; |
|
326 | }; | |
316 |
return cont |
|
327 | return cont; | |
317 | }; |
|
328 | }; | |
318 |
|
329 | |||
319 | CodeCell.prototype.render = function () { |
|
330 | CodeCell.prototype.render = function () { | |
320 |
var cont |
|
331 | var cont = IPython.Cell.prototype.render.apply(this); | |
321 | if (continue) { |
|
332 | console.log('CodeCell.render'); | |
322 | this.execute(); |
|
333 | // Always execute, even if we are already in the rendered state | |
323 |
|
|
334 | return cont; | |
324 | return continue; |
|
|||
325 | }; |
|
335 | }; | |
326 |
|
336 | |||
327 | CodeCell.prototype.unrender = function () { |
|
337 | CodeCell.prototype.unrender = function () { | |
328 | var continue = IPython.Cell.prototype.unrender.apply(this); |
|
338 | // CodeCell is always rendered | |
329 | if (continue) { |
|
339 | return false; | |
330 | this.clear_output(true, true, true); |
|
|||
331 | }; |
|
|||
332 | return continue; |
|
|||
333 | }; |
|
340 | }; | |
334 |
|
341 | |||
335 | CodeCell.prototype.command_mode = function () { |
|
342 | CodeCell.prototype.command_mode = function () { | |
336 |
var cont |
|
343 | var cont = IPython.Cell.prototype.command_mode.apply(this); | |
337 | if (continue) { |
|
344 | console.log('CodeCell.command_mode'); | |
|
345 | if (cont) { | |||
338 | this.focus_cell(); |
|
346 | this.focus_cell(); | |
339 | }; |
|
347 | }; | |
340 |
return cont |
|
348 | return cont; | |
341 | } |
|
349 | } | |
342 |
|
350 | |||
343 | CodeCell.prototype.edit_mode = function () { |
|
351 | CodeCell.prototype.edit_mode = function () { | |
344 |
var cont |
|
352 | var cont = IPython.Cell.prototype.edit_mode.apply(this); | |
345 | if (continue) { |
|
353 | console.log('CodeCell.edit_mode'); | |
|
354 | if (cont) { | |||
346 | this.focus_editor(); |
|
355 | this.focus_editor(); | |
347 | }; |
|
356 | }; | |
348 |
return cont |
|
357 | return cont; | |
349 | } |
|
358 | } | |
350 |
|
359 | |||
351 | CodeCell.prototype.select_all = function () { |
|
360 | CodeCell.prototype.select_all = function () { |
@@ -39,6 +39,8 b' var IPython = (function (IPython) {' | |||||
39 | this.undelete_index = null; |
|
39 | this.undelete_index = null; | |
40 | this.undelete_below = false; |
|
40 | this.undelete_below = false; | |
41 | this.paste_enabled = false; |
|
41 | this.paste_enabled = false; | |
|
42 | this.mode = 'command'; | |||
|
43 | this.edit_index = null; | |||
42 | this.set_dirty(false); |
|
44 | this.set_dirty(false); | |
43 | this.metadata = {}; |
|
45 | this.metadata = {}; | |
44 | this._checkpoint_after_save = false; |
|
46 | this._checkpoint_after_save = false; | |
@@ -74,7 +76,7 b' var IPython = (function (IPython) {' | |||||
74 | * @method baseProjectUrl |
|
76 | * @method baseProjectUrl | |
75 | * @return {String} The base project URL |
|
77 | * @return {String} The base project URL | |
76 | */ |
|
78 | */ | |
77 | Notebook.prototype.baseProjectUrl = function(){ |
|
79 | Notebook.prototype.baseProjectUrl = function() { | |
78 | return this._baseProjectUrl || $('body').data('baseProjectUrl'); |
|
80 | return this._baseProjectUrl || $('body').data('baseProjectUrl'); | |
79 | }; |
|
81 | }; | |
80 |
|
82 | |||
@@ -131,6 +133,12 b' var IPython = (function (IPython) {' | |||||
131 | var index = that.find_cell_index(data.cell); |
|
133 | var index = that.find_cell_index(data.cell); | |
132 | that.select(index); |
|
134 | that.select(index); | |
133 | }); |
|
135 | }); | |
|
136 | ||||
|
137 | $([IPython.events]).on('edit_mode.Cell', function (event, data) { | |||
|
138 | var index = that.find_cell_index(data.cell); | |||
|
139 | that.select(index); | |||
|
140 | that.edit_mode(); | |||
|
141 | }); | |||
134 |
|
142 | |||
135 | $([IPython.events]).on('status_autorestarting.Kernel', function () { |
|
143 | $([IPython.events]).on('status_autorestarting.Kernel', function () { | |
136 | IPython.dialog.modal({ |
|
144 | IPython.dialog.modal({ | |
@@ -144,220 +152,222 b' var IPython = (function (IPython) {' | |||||
144 | }); |
|
152 | }); | |
145 | }); |
|
153 | }); | |
146 |
|
154 | |||
147 |
|
||||
148 | $(document).keydown(function (event) { |
|
155 | $(document).keydown(function (event) { | |
149 |
|
156 | |||
150 | // Save (CTRL+S) or (AppleKey+S) |
|
157 | // Event handlers for both command and edit mode | |
151 | //metaKey = applekey on mac |
|
|||
152 | if ((event.ctrlKey || event.metaKey) && event.keyCode==83) { |
|
158 | if ((event.ctrlKey || event.metaKey) && event.keyCode==83) { | |
|
159 | // Save (CTRL+S) or (Command+S on Mac) | |||
153 | that.save_checkpoint(); |
|
160 | that.save_checkpoint(); | |
154 | event.preventDefault(); |
|
161 | event.preventDefault(); | |
155 | return false; |
|
162 | return false; | |
156 | } else if (event.which === key.ESC) { |
|
163 | } else if (event.which === key.ESC) { | |
157 | // Intercept escape at highest level to avoid closing |
|
164 | // Intercept escape at highest level to avoid closing | |
158 | // websocket connection with firefox |
|
165 | // websocket connection with firefox | |
159 | IPython.pager.collapse(); |
|
|||
160 | event.preventDefault(); |
|
166 | event.preventDefault(); | |
|
167 | // Don't return yet to allow edit/command modes to handle | |||
161 | } else if (event.which === key.SHIFT) { |
|
168 | } else if (event.which === key.SHIFT) { | |
162 | // ignore shift keydown |
|
169 | // ignore shift keydown | |
163 | return true; |
|
170 | return true; | |
164 | } |
|
|||
165 | if (event.which === key.UPARROW && !event.shiftKey) { |
|
|||
166 | var cell = that.get_selected_cell(); |
|
|||
167 | if (cell && cell.at_top()) { |
|
|||
168 | event.preventDefault(); |
|
|||
169 | that.select_prev(); |
|
|||
170 | }; |
|
|||
171 | } else if (event.which === key.DOWNARROW && !event.shiftKey) { |
|
|||
172 | var cell = that.get_selected_cell(); |
|
|||
173 | if (cell && cell.at_bottom()) { |
|
|||
174 | event.preventDefault(); |
|
|||
175 | that.select_next(); |
|
|||
176 | }; |
|
|||
177 | } else if (event.which === key.ENTER && event.shiftKey) { |
|
171 | } else if (event.which === key.ENTER && event.shiftKey) { | |
178 | that.execute_selected_cell(); |
|
172 | that.execute_selected_cell('shift'); | |
179 | return false; |
|
173 | return false; | |
180 | } else if (event.which === key.ENTER && event.altKey) { |
|
174 | } else if (event.which === key.ENTER && event.altKey) { | |
181 | // Execute code cell, and insert new in place |
|
175 | // Execute code cell, and insert new in place | |
182 | that.execute_selected_cell(); |
|
176 | that.execute_selected_cell('alt'); | |
183 | // Only insert a new cell, if we ended up in an already populated cell |
|
|||
184 | if (/\S/.test(that.get_selected_cell().get_text()) == true) { |
|
|||
185 | that.insert_cell_above('code'); |
|
|||
186 | } |
|
|||
187 | return false; |
|
177 | return false; | |
188 | } else if (event.which === key.ENTER && event.ctrlKey) { |
|
178 | } else if (event.which === key.ENTER && event.ctrlKey) { | |
189 |
that.execute_selected_cell( |
|
179 | that.execute_selected_cell('ctrl'); | |
190 | return false; |
|
|||
191 | } else if (event.which === 77 && event.ctrlKey && that.control_key_active == false) { |
|
|||
192 | that.control_key_active = true; |
|
|||
193 | return false; |
|
|||
194 | } else if (event.which === 88 && that.control_key_active) { |
|
|||
195 | // Cut selected cell = x |
|
|||
196 | that.cut_cell(); |
|
|||
197 | that.control_key_active = false; |
|
|||
198 | return false; |
|
|||
199 | } else if (event.which === 67 && that.control_key_active) { |
|
|||
200 | // Copy selected cell = c |
|
|||
201 | that.copy_cell(); |
|
|||
202 | that.control_key_active = false; |
|
|||
203 | return false; |
|
|||
204 | } else if (event.which === 86 && that.control_key_active) { |
|
|||
205 | // Paste below selected cell = v |
|
|||
206 | that.paste_cell_below(); |
|
|||
207 | that.control_key_active = false; |
|
|||
208 | return false; |
|
|||
209 | } else if (event.which === 68 && that.control_key_active) { |
|
|||
210 | // Delete selected cell = d |
|
|||
211 | that.delete_cell(); |
|
|||
212 | that.control_key_active = false; |
|
|||
213 | return false; |
|
|||
214 | } else if (event.which === 65 && that.control_key_active) { |
|
|||
215 | // Insert code cell above selected = a |
|
|||
216 | that.insert_cell_above('code'); |
|
|||
217 | that.control_key_active = false; |
|
|||
218 | return false; |
|
|||
219 | } else if (event.which === 66 && that.control_key_active) { |
|
|||
220 | // Insert code cell below selected = b |
|
|||
221 | that.insert_cell_below('code'); |
|
|||
222 | that.control_key_active = false; |
|
|||
223 | return false; |
|
|||
224 | } else if (event.which === 89 && that.control_key_active) { |
|
|||
225 | // To code = y |
|
|||
226 | that.to_code(); |
|
|||
227 | that.control_key_active = false; |
|
|||
228 | return false; |
|
|||
229 | } else if (event.which === 77 && that.control_key_active) { |
|
|||
230 | // To markdown = m |
|
|||
231 | that.to_markdown(); |
|
|||
232 | that.control_key_active = false; |
|
|||
233 | return false; |
|
|||
234 | } else if (event.which === 84 && that.control_key_active) { |
|
|||
235 | // To Raw = t |
|
|||
236 | that.to_raw(); |
|
|||
237 | that.control_key_active = false; |
|
|||
238 | return false; |
|
180 | return false; | |
239 | } else if (event.which === 49 && that.control_key_active) { |
|
|||
240 | // To Heading 1 = 1 |
|
|||
241 | that.to_heading(undefined, 1); |
|
|||
242 | that.control_key_active = false; |
|
|||
243 | return false; |
|
|||
244 | } else if (event.which === 50 && that.control_key_active) { |
|
|||
245 | // To Heading 2 = 2 |
|
|||
246 | that.to_heading(undefined, 2); |
|
|||
247 | that.control_key_active = false; |
|
|||
248 | return false; |
|
|||
249 | } else if (event.which === 51 && that.control_key_active) { |
|
|||
250 | // To Heading 3 = 3 |
|
|||
251 | that.to_heading(undefined, 3); |
|
|||
252 | that.control_key_active = false; |
|
|||
253 | return false; |
|
|||
254 | } else if (event.which === 52 && that.control_key_active) { |
|
|||
255 | // To Heading 4 = 4 |
|
|||
256 | that.to_heading(undefined, 4); |
|
|||
257 | that.control_key_active = false; |
|
|||
258 | return false; |
|
|||
259 | } else if (event.which === 53 && that.control_key_active) { |
|
|||
260 | // To Heading 5 = 5 |
|
|||
261 | that.to_heading(undefined, 5); |
|
|||
262 | that.control_key_active = false; |
|
|||
263 | return false; |
|
|||
264 | } else if (event.which === 54 && that.control_key_active) { |
|
|||
265 | // To Heading 6 = 6 |
|
|||
266 | that.to_heading(undefined, 6); |
|
|||
267 | that.control_key_active = false; |
|
|||
268 | return false; |
|
|||
269 | } else if (event.which === 79 && that.control_key_active) { |
|
|||
270 | // Toggle output = o |
|
|||
271 | if (event.shiftKey){ |
|
|||
272 | that.toggle_output_scroll(); |
|
|||
273 | } else { |
|
|||
274 | that.toggle_output(); |
|
|||
275 | } |
|
|||
276 | that.control_key_active = false; |
|
|||
277 | return false; |
|
|||
278 | } else if (event.which === 83 && that.control_key_active) { |
|
|||
279 | // Save notebook = s |
|
|||
280 | that.save_checkpoint(); |
|
|||
281 | that.control_key_active = false; |
|
|||
282 | return false; |
|
|||
283 | } else if (event.which === 74 && that.control_key_active) { |
|
|||
284 | // Move cell down = j |
|
|||
285 | that.move_cell_down(); |
|
|||
286 | that.control_key_active = false; |
|
|||
287 | return false; |
|
|||
288 | } else if (event.which === 75 && that.control_key_active) { |
|
|||
289 | // Move cell up = k |
|
|||
290 | that.move_cell_up(); |
|
|||
291 | that.control_key_active = false; |
|
|||
292 | return false; |
|
|||
293 | } else if (event.which === 80 && that.control_key_active) { |
|
|||
294 | // Select previous = p |
|
|||
295 | that.select_prev(); |
|
|||
296 | that.control_key_active = false; |
|
|||
297 | return false; |
|
|||
298 | } else if (event.which === 78 && that.control_key_active) { |
|
|||
299 | // Select next = n |
|
|||
300 | that.select_next(); |
|
|||
301 | that.control_key_active = false; |
|
|||
302 | return false; |
|
|||
303 | } else if (event.which === 76 && that.control_key_active) { |
|
|||
304 | // Toggle line numbers = l |
|
|||
305 | that.cell_toggle_line_numbers(); |
|
|||
306 | that.control_key_active = false; |
|
|||
307 | return false; |
|
|||
308 | } else if (event.which === 73 && that.control_key_active) { |
|
|||
309 | // Interrupt kernel = i |
|
|||
310 | that.session.interrupt_kernel(); |
|
|||
311 | that.control_key_active = false; |
|
|||
312 | return false; |
|
|||
313 | } else if (event.which === 190 && that.control_key_active) { |
|
|||
314 | // Restart kernel = . # matches qt console |
|
|||
315 | that.restart_kernel(); |
|
|||
316 | that.control_key_active = false; |
|
|||
317 | return false; |
|
|||
318 | } else if (event.which === 72 && that.control_key_active) { |
|
|||
319 | // Show keyboard shortcuts = h |
|
|||
320 | IPython.quick_help.show_keyboard_shortcuts(); |
|
|||
321 | that.control_key_active = false; |
|
|||
322 | return false; |
|
|||
323 | } else if (event.which === 90 && that.control_key_active) { |
|
|||
324 | // Undo last cell delete = z |
|
|||
325 | that.undelete(); |
|
|||
326 | that.control_key_active = false; |
|
|||
327 | return false; |
|
|||
328 | } else if ((event.which === 189 || event.which === 173) && |
|
|||
329 | that.control_key_active) { |
|
|||
330 | // how fun! '-' is 189 in Chrome, but 173 in FF and Opera |
|
|||
331 | // Split cell = - |
|
|||
332 | that.split_cell(); |
|
|||
333 | that.control_key_active = false; |
|
|||
334 | return false; |
|
|||
335 | } else if (that.control_key_active) { |
|
|||
336 | that.control_key_active = false; |
|
|||
337 | return true; |
|
|||
338 | } |
|
181 | } | |
|
182 | ||||
|
183 | // Event handlers for edit mode | |||
|
184 | if (that.mode === 'edit') { | |||
|
185 | if (event.which === key.ESC) { | |||
|
186 | // ESC | |||
|
187 | that.command_mode(); | |||
|
188 | return false; | |||
|
189 | } else if (event.which === 77 && event.ctrlKey) { | |||
|
190 | // Ctrl-m | |||
|
191 | that.command_mode(); | |||
|
192 | return false; | |||
|
193 | } else if (event.which === key.UPARROW && !event.shiftKey) { | |||
|
194 | var cell = that.get_selected_cell(); | |||
|
195 | if (cell && cell.at_top()) { | |||
|
196 | event.preventDefault(); | |||
|
197 | that.command_mode() | |||
|
198 | that.select_prev(); | |||
|
199 | that.edit_mode(); | |||
|
200 | return false; | |||
|
201 | }; | |||
|
202 | } else if (event.which === key.DOWNARROW && !event.shiftKey) { | |||
|
203 | var cell = that.get_selected_cell(); | |||
|
204 | if (cell && cell.at_bottom()) { | |||
|
205 | event.preventDefault(); | |||
|
206 | that.command_mode() | |||
|
207 | that.select_next(); | |||
|
208 | that.edit_mode(); | |||
|
209 | return false; | |||
|
210 | }; | |||
|
211 | }; | |||
|
212 | // Event handlers for command mode | |||
|
213 | } else if (that.mode === 'command' && !(event.ctrlKey || event.altKey)) { | |||
|
214 | if (event.which === key.ENTER && !(event.ctrlKey || event.altKey || event.shiftKey)) { | |||
|
215 | // Enter edit mode = ENTER alone | |||
|
216 | that.edit_mode(); | |||
|
217 | return false | |||
|
218 | } else if (event.which === key.UPARROW && !event.shiftKey) { | |||
|
219 | var index = that.get_selected_index(); | |||
|
220 | if (index !== 0 && index !== null) { | |||
|
221 | that.select_prev(); | |||
|
222 | var cell = that.get_selected_cell(); | |||
|
223 | cell.focus_cell(); | |||
|
224 | }; | |||
|
225 | return false; | |||
|
226 | } else if (event.which === key.DOWNARROW && !event.shiftKey) { | |||
|
227 | var index = that.get_selected_index(); | |||
|
228 | if (index !== (that.ncells()-1) && index !== null) { | |||
|
229 | that.select_next(); | |||
|
230 | var cell = that.get_selected_cell(); | |||
|
231 | cell.focus_cell(); | |||
|
232 | }; | |||
|
233 | return false; | |||
|
234 | } else if (event.which === 88) { | |||
|
235 | // Cut selected cell = x | |||
|
236 | that.cut_cell(); | |||
|
237 | return false; | |||
|
238 | } else if (event.which === 67) { | |||
|
239 | // Copy selected cell = c | |||
|
240 | that.copy_cell(); | |||
|
241 | return false; | |||
|
242 | } else if (event.which === 86) { | |||
|
243 | // Paste below selected cell = v | |||
|
244 | that.paste_cell_below(); | |||
|
245 | return false; | |||
|
246 | } else if (event.which === 68) { | |||
|
247 | // Delete selected cell = d | |||
|
248 | that.delete_cell(); | |||
|
249 | return false; | |||
|
250 | } else if (event.which === 65) { | |||
|
251 | // Insert code cell above selected = a | |||
|
252 | that.insert_cell_above('code'); | |||
|
253 | that.select_prev(); | |||
|
254 | return false; | |||
|
255 | } else if (event.which === 66) { | |||
|
256 | // Insert code cell below selected = b | |||
|
257 | that.insert_cell_below('code'); | |||
|
258 | that.select_next(); | |||
|
259 | return false; | |||
|
260 | } else if (event.which === 89) { | |||
|
261 | // To code = y | |||
|
262 | that.to_code(); | |||
|
263 | return false; | |||
|
264 | } else if (event.which === 77) { | |||
|
265 | // To markdown = m | |||
|
266 | that.to_markdown(); | |||
|
267 | return false; | |||
|
268 | } else if (event.which === 84) { | |||
|
269 | // To Raw = t | |||
|
270 | that.to_raw(); | |||
|
271 | return false; | |||
|
272 | } else if (event.which === 49) { | |||
|
273 | // To Heading 1 = 1 | |||
|
274 | that.to_heading(undefined, 1); | |||
|
275 | return false; | |||
|
276 | } else if (event.which === 50) { | |||
|
277 | // To Heading 2 = 2 | |||
|
278 | that.to_heading(undefined, 2); | |||
|
279 | return false; | |||
|
280 | } else if (event.which === 51) { | |||
|
281 | // To Heading 3 = 3 | |||
|
282 | that.to_heading(undefined, 3); | |||
|
283 | return false; | |||
|
284 | } else if (event.which === 52) { | |||
|
285 | // To Heading 4 = 4 | |||
|
286 | that.to_heading(undefined, 4); | |||
|
287 | return false; | |||
|
288 | } else if (event.which === 53) { | |||
|
289 | // To Heading 5 = 5 | |||
|
290 | that.to_heading(undefined, 5); | |||
|
291 | return false; | |||
|
292 | } else if (event.which === 54) { | |||
|
293 | // To Heading 6 = 6 | |||
|
294 | that.to_heading(undefined, 6); | |||
|
295 | return false; | |||
|
296 | } else if (event.which === 79) { | |||
|
297 | // Toggle output = o | |||
|
298 | if (event.shiftKey) { | |||
|
299 | that.toggle_output_scroll(); | |||
|
300 | } else { | |||
|
301 | that.toggle_output(); | |||
|
302 | }; | |||
|
303 | return false; | |||
|
304 | } else if (event.which === 83) { | |||
|
305 | // Save notebook = s | |||
|
306 | that.save_checkpoint(); | |||
|
307 | that.control_key_active = false; | |||
|
308 | return false; | |||
|
309 | } else if (event.which === 74) { | |||
|
310 | // Move cell down = j | |||
|
311 | that.move_cell_down(); | |||
|
312 | return false; | |||
|
313 | } else if (event.which === 75) { | |||
|
314 | // Move cell up = k | |||
|
315 | that.move_cell_up(); | |||
|
316 | return false; | |||
|
317 | } else if (event.which === 80) { | |||
|
318 | // Select previous = p | |||
|
319 | that.select_prev(); | |||
|
320 | return false; | |||
|
321 | } else if (event.which === 78) { | |||
|
322 | // Select next = n | |||
|
323 | that.select_next(); | |||
|
324 | return false; | |||
|
325 | } else if (event.which === 76) { | |||
|
326 | // Toggle line numbers = l | |||
|
327 | that.cell_toggle_line_numbers(); | |||
|
328 | return false; | |||
|
329 | } else if (event.which === 73) { | |||
|
330 | // Interrupt kernel = i | |||
|
331 | that.kernel.interrupt(); | |||
|
332 | return false; | |||
|
333 | } else if (event.which === 190) { | |||
|
334 | // Restart kernel = . # matches qt console | |||
|
335 | that.restart_kernel(); | |||
|
336 | return false; | |||
|
337 | } else if (event.which === 72) { | |||
|
338 | // Show keyboard shortcuts = h | |||
|
339 | IPython.quick_help.show_keyboard_shortcuts(); | |||
|
340 | return false; | |||
|
341 | } else if (event.which === 90) { | |||
|
342 | // Undo last cell delete = z | |||
|
343 | that.undelete(); | |||
|
344 | return false; | |||
|
345 | }; | |||
|
346 | }; | |||
|
347 | ||||
|
348 | // If we havn't handled it, let someone else. | |||
339 | return true; |
|
349 | return true; | |
340 | }); |
|
350 | }); | |
341 |
|
351 | |||
342 | var collapse_time = function(time){ |
|
352 | var collapse_time = function (time) { | |
343 | var app_height = $('#ipython-main-app').height(); // content height |
|
353 | var app_height = $('#ipython-main-app').height(); // content height | |
344 | var splitter_height = $('div#pager_splitter').outerHeight(true); |
|
354 | var splitter_height = $('div#pager_splitter').outerHeight(true); | |
345 | var new_height = app_height - splitter_height; |
|
355 | var new_height = app_height - splitter_height; | |
346 | that.element.animate({height : new_height + 'px'}, time); |
|
356 | that.element.animate({height : new_height + 'px'}, time); | |
347 | } |
|
357 | }; | |
348 |
|
358 | |||
349 | this.element.bind('collapse_pager', function (event,extrap) { |
|
359 | this.element.bind('collapse_pager', function (event, extrap) { | |
350 | var time = (extrap != undefined) ? ((extrap.duration != undefined ) ? extrap.duration : 'fast') : 'fast'; |
|
360 | var time = (extrap != undefined) ? ((extrap.duration != undefined ) ? extrap.duration : 'fast') : 'fast'; | |
351 | collapse_time(time); |
|
361 | collapse_time(time); | |
352 | }); |
|
362 | }); | |
353 |
|
363 | |||
354 | var expand_time = function(time) { |
|
364 | var expand_time = function (time) { | |
355 | var app_height = $('#ipython-main-app').height(); // content height |
|
365 | var app_height = $('#ipython-main-app').height(); // content height | |
356 | var splitter_height = $('div#pager_splitter').outerHeight(true); |
|
366 | var splitter_height = $('div#pager_splitter').outerHeight(true); | |
357 | var pager_height = $('div#pager').outerHeight(true); |
|
367 | var pager_height = $('div#pager').outerHeight(true); | |
358 | var new_height = app_height - pager_height - splitter_height; |
|
368 | var new_height = app_height - pager_height - splitter_height; | |
359 | that.element.animate({height : new_height + 'px'}, time); |
|
369 | that.element.animate({height : new_height + 'px'}, time); | |
360 | } |
|
370 | }; | |
361 |
|
371 | |||
362 | this.element.bind('expand_pager', function (event, extrap) { |
|
372 | this.element.bind('expand_pager', function (event, extrap) { | |
363 | var time = (extrap != undefined) ? ((extrap.duration != undefined ) ? extrap.duration : 'fast') : 'fast'; |
|
373 | var time = (extrap != undefined) ? ((extrap.duration != undefined ) ? extrap.duration : 'fast') : 'fast'; | |
@@ -653,6 +663,7 b' var IPython = (function (IPython) {' | |||||
653 | this.get_cell(sindex).unselect(); |
|
663 | this.get_cell(sindex).unselect(); | |
654 | }; |
|
664 | }; | |
655 | var cell = this.get_cell(index); |
|
665 | var cell = this.get_cell(index); | |
|
666 | console.log('Notebook.select', index); | |||
656 | cell.select(); |
|
667 | cell.select(); | |
657 | if (cell.cell_type === 'heading') { |
|
668 | if (cell.cell_type === 'heading') { | |
658 | $([IPython.events]).trigger('selected_cell_type_changed.Notebook', |
|
669 | $([IPython.events]).trigger('selected_cell_type_changed.Notebook', | |
@@ -692,6 +703,48 b' var IPython = (function (IPython) {' | |||||
692 | }; |
|
703 | }; | |
693 |
|
704 | |||
694 |
|
705 | |||
|
706 | // Edit/Command mode | |||
|
707 | ||||
|
708 | /** | |||
|
709 | * Enter command mode for the currently selected cell | |||
|
710 | * | |||
|
711 | * @method command_mode | |||
|
712 | */ | |||
|
713 | Notebook.prototype.command_mode = function () { | |||
|
714 | console.log('Notebook.command_mode', this.mode, this.edit_index); | |||
|
715 | if (this.mode !== 'command') { | |||
|
716 | var cell = this.get_cell(this.edit_index); | |||
|
717 | if (cell) { | |||
|
718 | cell.command_mode(); | |||
|
719 | this.mode = 'command'; | |||
|
720 | this.edit_index = null; | |||
|
721 | }; | |||
|
722 | }; | |||
|
723 | }; | |||
|
724 | ||||
|
725 | /** | |||
|
726 | * Enter edit mode for the currently selected cell | |||
|
727 | * | |||
|
728 | * @method editmode | |||
|
729 | */ | |||
|
730 | Notebook.prototype.edit_mode = function () { | |||
|
731 | var index = this.get_selected_index(); | |||
|
732 | console.log('Notebook.edit_mode', this.mode, index); | |||
|
733 | if (index !== this.edit_index) { | |||
|
734 | if (this.edit_index !== null) { | |||
|
735 | var old_cell = this.get_cell(this.edit_index) | |||
|
736 | old_cell.command_mode(); | |||
|
737 | } | |||
|
738 | var cell = this.get_cell(index); | |||
|
739 | if (cell) { | |||
|
740 | cell.edit_mode(); | |||
|
741 | this.mode = 'edit'; | |||
|
742 | this.edit_index = index; | |||
|
743 | }; | |||
|
744 | }; | |||
|
745 | }; | |||
|
746 | ||||
|
747 | ||||
695 | // Cell movement |
|
748 | // Cell movement | |
696 |
|
749 | |||
697 | /** |
|
750 | /** | |
@@ -804,10 +857,12 b' var IPython = (function (IPython) {' | |||||
804 | cell = new IPython.HeadingCell(); |
|
857 | cell = new IPython.HeadingCell(); | |
805 | } |
|
858 | } | |
806 |
|
859 | |||
807 | if(this._insert_element_at_index(cell.element,index)){ |
|
860 | if(this._insert_element_at_index(cell.element,index)) { | |
808 | cell.render(); |
|
861 | cell.render(); | |
809 | this.select(this.find_cell_index(cell)); |
|
|||
810 | $([IPython.events]).trigger('create.Cell', {'cell': cell, 'index': index}); |
|
862 | $([IPython.events]).trigger('create.Cell', {'cell': cell, 'index': index}); | |
|
863 | cell.refresh(); | |||
|
864 | // TODO: should we really get rid of this? | |||
|
865 | //this.select(this.find_cell_index(cell)); | |||
811 | this.set_dirty(true); |
|
866 | this.set_dirty(true); | |
812 | } |
|
867 | } | |
813 | } |
|
868 | } | |
@@ -952,6 +1007,8 b' var IPython = (function (IPython) {' | |||||
952 | // to this state, instead of a blank cell |
|
1007 | // to this state, instead of a blank cell | |
953 | target_cell.code_mirror.clearHistory(); |
|
1008 | target_cell.code_mirror.clearHistory(); | |
954 | source_element.remove(); |
|
1009 | source_element.remove(); | |
|
1010 | this.select(i); | |||
|
1011 | this.edit_mode(); | |||
955 | this.set_dirty(true); |
|
1012 | this.set_dirty(true); | |
956 | }; |
|
1013 | }; | |
957 | }; |
|
1014 | }; | |
@@ -1440,31 +1497,41 b' var IPython = (function (IPython) {' | |||||
1440 | * @method execute_selected_cell |
|
1497 | * @method execute_selected_cell | |
1441 | * @param {Object} options Customize post-execution behavior |
|
1498 | * @param {Object} options Customize post-execution behavior | |
1442 | */ |
|
1499 | */ | |
1443 |
Notebook.prototype.execute_selected_cell = function ( |
|
1500 | Notebook.prototype.execute_selected_cell = function (mode) { | |
1444 | // add_new: should a new cell be added if we are at the end of the nb |
|
1501 | // mode = shift, ctrl, alt | |
1445 | // terminal: execute in terminal mode, which stays in the current cell |
|
1502 | mode = mode || 'shift' | |
1446 | var default_options = {terminal: false, add_new: true}; |
|
|||
1447 | $.extend(default_options, options); |
|
|||
1448 | var that = this; |
|
1503 | var that = this; | |
1449 | var cell = that.get_selected_cell(); |
|
1504 | var cell = that.get_selected_cell(); | |
1450 | var cell_index = that.find_cell_index(cell); |
|
1505 | var cell_index = that.find_cell_index(cell); | |
1451 | if (cell instanceof IPython.CodeCell) { |
|
1506 | ||
1452 |
|
|
1507 | cell.execute(); | |
1453 | } |
|
1508 | console.log('Notebook.execute_selected_cell', mode); | |
1454 | if (default_options.terminal) { |
|
1509 | if (mode === 'shift') { | |
1455 | cell.select_all(); |
|
1510 | if (cell_index === (that.ncells()-1)) { | |
1456 | } else { |
|
|||
1457 | if ((cell_index === (that.ncells()-1)) && default_options.add_new) { |
|
|||
1458 | that.insert_cell_below('code'); |
|
1511 | that.insert_cell_below('code'); | |
1459 | // If we are adding a new cell at the end, scroll down to show it. |
|
1512 | that.select(cell_index+1); | |
|
1513 | that.edit_mode(); | |||
1460 | that.scroll_to_bottom(); |
|
1514 | that.scroll_to_bottom(); | |
1461 | } else { |
|
1515 | } else { | |
1462 |
that. |
|
1516 | that.command_mode(); | |
1463 |
} |
|
1517 | } | |
1464 | }; |
|
1518 | } else if (mode === 'ctrl') { | |
|
1519 | that.select(cell_index+1); | |||
|
1520 | that.get_cell(cell_index+1).focus_cell(); | |||
|
1521 | } else if (mode === 'alt') { | |||
|
1522 | // Only insert a new cell, if we ended up in an already populated cell | |||
|
1523 | if (/\S/.test(that.get_next_cell().get_text()) == true) { | |||
|
1524 | that.insert_cell_below('code'); | |||
|
1525 | } | |||
|
1526 | var next_index = cell_index+1; | |||
|
1527 | that.select(cell_index+1); | |||
|
1528 | that.edit_mode(); | |||
|
1529 | } | |||
|
1530 | ||||
1465 | this.set_dirty(true); |
|
1531 | this.set_dirty(true); | |
1466 | }; |
|
1532 | }; | |
1467 |
|
1533 | |||
|
1534 | ||||
1468 | /** |
|
1535 | /** | |
1469 | * Execute all cells below the selected cell. |
|
1536 | * Execute all cells below the selected cell. | |
1470 | * |
|
1537 | * | |
@@ -1909,9 +1976,13 b' var IPython = (function (IPython) {' | |||||
1909 | this.fromJSON(data); |
|
1976 | this.fromJSON(data); | |
1910 | if (this.ncells() === 0) { |
|
1977 | if (this.ncells() === 0) { | |
1911 | this.insert_cell_below('code'); |
|
1978 | this.insert_cell_below('code'); | |
|
1979 | this.select(0); | |||
|
1980 | this.edit_mode(); | |||
|
1981 | } else { | |||
|
1982 | this.select(0); | |||
|
1983 | this.command_mode(); | |||
1912 | }; |
|
1984 | }; | |
1913 | this.set_dirty(false); |
|
1985 | this.set_dirty(false); | |
1914 | this.select(0); |
|
|||
1915 | this.scroll_to_top(); |
|
1986 | this.scroll_to_top(); | |
1916 | if (data.orig_nbformat !== undefined && data.nbformat !== data.orig_nbformat) { |
|
1987 | if (data.orig_nbformat !== undefined && data.nbformat !== data.orig_nbformat) { | |
1917 | var msg = "This notebook has been converted from an older " + |
|
1988 | var msg = "This notebook has been converted from an older " + |
@@ -64,7 +64,6 b' var IPython = (function (IPython) {' | |||||
64 | }; |
|
64 | }; | |
65 |
|
65 | |||
66 |
|
66 | |||
67 |
|
||||
68 | /** |
|
67 | /** | |
69 | * Create the DOM element of the TextCell |
|
68 | * Create the DOM element of the TextCell | |
70 | * @method create_element |
|
69 | * @method create_element | |
@@ -101,6 +100,8 b' var IPython = (function (IPython) {' | |||||
101 | TextCell.prototype.bind_events = function () { |
|
100 | TextCell.prototype.bind_events = function () { | |
102 | IPython.Cell.prototype.bind_events.apply(this); |
|
101 | IPython.Cell.prototype.bind_events.apply(this); | |
103 | var that = this; |
|
102 | var that = this; | |
|
103 | ||||
|
104 | // TODO: move this to the notebook event handler | |||
104 | this.element.keydown(function (event) { |
|
105 | this.element.keydown(function (event) { | |
105 | if (event.which === 13 && !event.shiftKey) { |
|
106 | if (event.which === 13 && !event.shiftKey) { | |
106 | if (that.rendered) { |
|
107 | if (that.rendered) { | |
@@ -109,11 +110,13 b' var IPython = (function (IPython) {' | |||||
109 | }; |
|
110 | }; | |
110 | }; |
|
111 | }; | |
111 | }); |
|
112 | }); | |
|
113 | ||||
112 | this.element.dblclick(function () { |
|
114 | this.element.dblclick(function () { | |
113 | that.unrender(); |
|
115 | that.unrender(); | |
114 | }); |
|
116 | }); | |
115 | }; |
|
117 | }; | |
116 |
|
118 | |||
|
119 | ||||
117 | /** |
|
120 | /** | |
118 | * This method gets called in CodeMirror's onKeyDown/onKeyPress |
|
121 | * This method gets called in CodeMirror's onKeyDown/onKeyPress | |
119 | * handlers and is used to provide custom key handling. |
|
122 | * handlers and is used to provide custom key handling. | |
@@ -126,38 +129,34 b' var IPython = (function (IPython) {' | |||||
126 | * @return {Boolean} `true` if CodeMirror should ignore the event, `false` Otherwise |
|
129 | * @return {Boolean} `true` if CodeMirror should ignore the event, `false` Otherwise | |
127 | */ |
|
130 | */ | |
128 | TextCell.prototype.handle_codemirror_keyevent = function (editor, event) { |
|
131 | TextCell.prototype.handle_codemirror_keyevent = function (editor, event) { | |
129 |
|
132 | if (this.mode === 'command') { | ||
130 | if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) { |
|
133 | return false | |
131 | // Always ignore shift-enter in CodeMirror as we handle it. |
|
134 | } else if (this.mode === 'edit') { | |
132 | return true; |
|
135 | if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) { | |
133 | } |
|
136 | // Always ignore shift-enter in CodeMirror as we handle it. | |
|
137 | return true; | |||
|
138 | }; | |||
|
139 | return false; | |||
|
140 | }; | |||
134 | return false; |
|
141 | return false; | |
135 | }; |
|
142 | }; | |
136 |
|
143 | |||
137 | // Cell level actions |
|
144 | // Cell level actions | |
138 |
|
145 | |||
139 | TextCell.prototype.select = function () { |
|
146 | TextCell.prototype.select = function () { | |
140 |
var cont |
|
147 | var cont = IPython.Cell.prototype.select.apply(this); | |
141 |
if (cont |
|
148 | if (cont) { | |
142 | if (this.mode === 'edit') { |
|
149 | if (this.mode === 'edit') { | |
143 | this.code_mirror.refresh(); |
|
150 | this.code_mirror.refresh(); | |
144 | } |
|
151 | } | |
145 | }; |
|
152 | }; | |
146 |
return cont |
|
153 | return cont; | |
147 | }; |
|
|||
148 |
|
||||
149 | TextCell.prototype.render = function () { |
|
|||
150 | var continue = IPython.Cell.prototype.render.apply(this); |
|
|||
151 | if (continue) { |
|
|||
152 | this.execute(); |
|
|||
153 | }; |
|
|||
154 | return continue; |
|
|||
155 | }; |
|
154 | }; | |
156 |
|
155 | |||
157 | TextCell.prototype.unrender = function () { |
|
156 | TextCell.prototype.unrender = function () { | |
158 | if (this.read_only) return; |
|
157 | if (this.read_only) return; | |
159 |
var cont |
|
158 | var cont = IPython.Cell.prototype.unrender.apply(this); | |
160 |
if (cont |
|
159 | if (cont) { | |
161 | var text_cell = this.element; |
|
160 | var text_cell = this.element; | |
162 | var output = text_cell.find("div.text_cell_render"); |
|
161 | var output = text_cell.find("div.text_cell_render"); | |
163 | output.hide(); |
|
162 | output.hide(); | |
@@ -169,23 +168,27 b' var IPython = (function (IPython) {' | |||||
169 | } |
|
168 | } | |
170 |
|
169 | |||
171 | }; |
|
170 | }; | |
172 |
return cont |
|
171 | return cont; | |
|
172 | }; | |||
|
173 | ||||
|
174 | TextCell.prototype.execute = function () { | |||
|
175 | this.render(); | |||
173 | }; |
|
176 | }; | |
174 |
|
177 | |||
175 | TextCell.prototype.command_mode = function () { |
|
178 | TextCell.prototype.command_mode = function () { | |
176 |
var cont |
|
179 | var cont = IPython.Cell.prototype.command_mode.apply(this); | |
177 |
if (cont |
|
180 | if (cont) { | |
178 | this.focus_cell(); |
|
181 | this.focus_cell(); | |
179 | }; |
|
182 | }; | |
180 |
return cont |
|
183 | return cont; | |
181 | } |
|
184 | } | |
182 |
|
185 | |||
183 | TextCell.prototype.edit_mode = function () { |
|
186 | TextCell.prototype.edit_mode = function () { | |
184 |
var cont |
|
187 | var cont = IPython.Cell.prototype.edit_mode.apply(this); | |
185 |
if (cont |
|
188 | if (cont) { | |
186 | this.focus_editor(); |
|
189 | this.focus_editor(); | |
187 | }; |
|
190 | }; | |
188 |
return cont |
|
191 | return cont; | |
189 | } |
|
192 | } | |
190 |
|
193 | |||
191 | /** |
|
194 | /** | |
@@ -224,36 +227,51 b' var IPython = (function (IPython) {' | |||||
224 | }; |
|
227 | }; | |
225 |
|
228 | |||
226 | /** |
|
229 | /** | |
227 | * not deprecated, but implementation wrong |
|
|||
228 | * @method at_top |
|
230 | * @method at_top | |
229 | * @deprecated |
|
231 | * @return {Boolean} | |
230 | * @return {Boolean} true is cell rendered, false otherwise |
|
|||
231 | * I doubt this is what it is supposed to do |
|
|||
232 | * this implementation is completly false |
|
|||
233 | */ |
|
232 | */ | |
234 | TextCell.prototype.at_top = function () { |
|
233 | TextCell.prototype.at_top = function () { | |
235 | if (this.rendered) { |
|
234 | if (this.rendered) { | |
236 | return true; |
|
235 | return true; | |
237 | } else { |
|
236 | } else { | |
238 | return false; |
|
237 | if (cursor.line === 0 && cursor.ch === 0) { | |
239 | } |
|
238 | return true; | |
|
239 | } else { | |||
|
240 | return false; | |||
|
241 | }; | |||
|
242 | }; | |||
240 | }; |
|
243 | }; | |
241 |
|
244 | |||
242 |
|
245 | |||
|
246 | /** @method at_bottom **/ | |||
|
247 | TextCell.prototype.at_bottom = function () { | |||
|
248 | if (this.rendered) { | |||
|
249 | return true | |||
|
250 | } else { | |||
|
251 | var cursor = this.code_mirror.getCursor(); | |||
|
252 | if (cursor.line === (this.code_mirror.lineCount()-1) && cursor.ch === this.code_mirror.getLine(cursor.line).length) { | |||
|
253 | return true; | |||
|
254 | } else { | |||
|
255 | return false; | |||
|
256 | }; | |||
|
257 | }; | |||
|
258 | }; | |||
|
259 | ||||
243 | /** |
|
260 | /** | |
244 | * not deprecated, but implementation wrong |
|
|||
245 | * @method at_bottom |
|
261 | * @method at_bottom | |
246 | * @deprecated |
|
262 | * @return {Boolean} | |
247 | * @return {Boolean} true is cell rendered, false otherwise |
|
|||
248 | * I doubt this is what it is supposed to do |
|
|||
249 | * this implementation is completly false |
|
|||
250 | * */ |
|
263 | * */ | |
251 | TextCell.prototype.at_bottom = function () { |
|
264 | TextCell.prototype.at_bottom = function () { | |
252 | if (this.rendered) { |
|
265 | if (this.rendered) { | |
253 | return true; |
|
266 | return true; | |
254 | } else { |
|
267 | } else { | |
255 | return false; |
|
268 | var cursor = this.code_mirror.getCursor(); | |
256 | } |
|
269 | if (cursor.line === (this.code_mirror.lineCount()-1) && cursor.ch === this.code_mirror.getLine(cursor.line).length) { | |
|
270 | return true; | |||
|
271 | } else { | |||
|
272 | return false; | |||
|
273 | }; | |||
|
274 | }; | |||
257 | }; |
|
275 | }; | |
258 |
|
276 | |||
259 | /** |
|
277 | /** | |
@@ -308,16 +326,14 b' var IPython = (function (IPython) {' | |||||
308 | placeholder: "Type *Markdown* and LaTeX: $\\alpha^2$" |
|
326 | placeholder: "Type *Markdown* and LaTeX: $\\alpha^2$" | |
309 | } |
|
327 | } | |
310 |
|
328 | |||
311 |
|
||||
312 |
|
||||
313 |
|
||||
314 | MarkdownCell.prototype = new TextCell(); |
|
329 | MarkdownCell.prototype = new TextCell(); | |
315 |
|
330 | |||
316 | /** |
|
331 | /** | |
317 | * @method render |
|
332 | * @method render | |
318 | */ |
|
333 | */ | |
319 | MarkdownCell.prototype.render = function () { |
|
334 | MarkdownCell.prototype.render = function () { | |
320 | if (this.rendered === false) { |
|
335 | var cont = IPython.TextCell.prototype.render.apply(this); | |
|
336 | if (cont) { | |||
321 | var text = this.get_text(); |
|
337 | var text = this.get_text(); | |
322 | var math = null; |
|
338 | var math = null; | |
323 | if (text === "") { text = this.placeholder; } |
|
339 | if (text === "") { text = this.placeholder; } | |
@@ -339,9 +355,9 b' var IPython = (function (IPython) {' | |||||
339 | } |
|
355 | } | |
340 | this.element.find('div.text_cell_input').hide(); |
|
356 | this.element.find('div.text_cell_input').hide(); | |
341 | this.element.find("div.text_cell_render").show(); |
|
357 | this.element.find("div.text_cell_render").show(); | |
342 |
this.typeset() |
|
358 | this.typeset() | |
343 | this.rendered = true; |
|
359 | }; | |
344 | } |
|
360 | return cont; | |
345 | }; |
|
361 | }; | |
346 |
|
362 | |||
347 |
|
363 | |||
@@ -357,11 +373,6 b' var IPython = (function (IPython) {' | |||||
357 |
|
373 | |||
358 | this.cell_type = 'raw'; |
|
374 | this.cell_type = 'raw'; | |
359 | TextCell.apply(this, [options]); |
|
375 | TextCell.apply(this, [options]); | |
360 |
|
||||
361 | var that = this; |
|
|||
362 | this.element.focusout( |
|
|||
363 | function() { that.auto_highlight(); } |
|
|||
364 | ); |
|
|||
365 | }; |
|
376 | }; | |
366 |
|
377 | |||
367 | RawCell.options_default = { |
|
378 | RawCell.options_default = { | |
@@ -370,10 +381,17 b' var IPython = (function (IPython) {' | |||||
370 | "When passing through nbconvert, a Raw Cell's content is added to the output unmodified." |
|
381 | "When passing through nbconvert, a Raw Cell's content is added to the output unmodified." | |
371 | }; |
|
382 | }; | |
372 |
|
383 | |||
373 |
|
||||
374 |
|
||||
375 | RawCell.prototype = new TextCell(); |
|
384 | RawCell.prototype = new TextCell(); | |
376 |
|
385 | |||
|
386 | /** @method bind_events **/ | |||
|
387 | RawCell.prototype.bind_events = function () { | |||
|
388 | TextCell.prototype.bind_events.apply(this); | |||
|
389 | var that = this | |||
|
390 | this.element.focusout(function() { | |||
|
391 | that.auto_highlight(); | |||
|
392 | }); | |||
|
393 | }; | |||
|
394 | ||||
377 | /** |
|
395 | /** | |
378 | * Trigger autodetection of highlight scheme for current cell |
|
396 | * Trigger autodetection of highlight scheme for current cell | |
379 | * @method auto_highlight |
|
397 | * @method auto_highlight | |
@@ -384,12 +402,13 b' var IPython = (function (IPython) {' | |||||
384 |
|
402 | |||
385 | /** @method render **/ |
|
403 | /** @method render **/ | |
386 | RawCell.prototype.render = function () { |
|
404 | RawCell.prototype.render = function () { | |
387 |
|
405 | // Make sure that this cell type can never be rendered | ||
388 |
this.rendered |
|
406 | if (this.rendered) { | |
|
407 | this.unrender(); | |||
|
408 | } | |||
389 | var text = this.get_text(); |
|
409 | var text = this.get_text(); | |
390 | if (text === "") { text = this.placeholder; } |
|
410 | if (text === "") { text = this.placeholder; } | |
391 | this.set_text(text); |
|
411 | this.set_text(text); | |
392 | this.unrender(); |
|
|||
393 | }; |
|
412 | }; | |
394 |
|
413 | |||
395 |
|
414 | |||
@@ -397,55 +416,34 b' var IPython = (function (IPython) {' | |||||
397 | RawCell.prototype.handle_codemirror_keyevent = function (editor, event) { |
|
416 | RawCell.prototype.handle_codemirror_keyevent = function (editor, event) { | |
398 |
|
417 | |||
399 | var that = this; |
|
418 | var that = this; | |
400 | if (event.which === key.UPARROW && event.type === 'keydown') { |
|
419 | if (this.mode === 'command') { | |
401 | // If we are not at the top, let CM handle the up arrow and |
|
420 | return false | |
402 | // prevent the global keydown handler from handling it. |
|
421 | } else if (this.mode === 'edit') { | |
403 | if (!that.at_top()) { |
|
422 | // TODO: review these handlers... | |
404 | event.stop(); |
|
423 | if (event.which === key.UPARROW && event.type === 'keydown') { | |
405 | return false; |
|
424 | // If we are not at the top, let CM handle the up arrow and | |
406 | } else { |
|
425 | // prevent the global keydown handler from handling it. | |
407 | return true; |
|
426 | if (!that.at_top()) { | |
408 | }; |
|
427 | event.stop(); | |
409 | } else if (event.which === key.DOWNARROW && event.type === 'keydown') { |
|
428 | return false; | |
410 | // If we are not at the bottom, let CM handle the down arrow and |
|
429 | } else { | |
411 | // prevent the global keydown handler from handling it. |
|
430 | return true; | |
412 | if (!that.at_bottom()) { |
|
431 | }; | |
413 | event.stop(); |
|
432 | } else if (event.which === key.DOWNARROW && event.type === 'keydown') { | |
414 | return false; |
|
433 | // If we are not at the bottom, let CM handle the down arrow and | |
415 | } else { |
|
434 | // prevent the global keydown handler from handling it. | |
416 | return true; |
|
435 | if (!that.at_bottom()) { | |
|
436 | event.stop(); | |||
|
437 | return false; | |||
|
438 | } else { | |||
|
439 | return true; | |||
|
440 | }; | |||
417 | }; |
|
441 | }; | |
|
442 | return false; | |||
418 | }; |
|
443 | }; | |
419 | return false; |
|
444 | return false; | |
420 | }; |
|
445 | }; | |
421 |
|
446 | |||
422 | /** @method select **/ |
|
|||
423 | RawCell.prototype.select = function () { |
|
|||
424 | IPython.Cell.prototype.select.apply(this); |
|
|||
425 | this.edit(); |
|
|||
426 | }; |
|
|||
427 |
|
||||
428 | /** @method at_top **/ |
|
|||
429 | RawCell.prototype.at_top = function () { |
|
|||
430 | var cursor = this.code_mirror.getCursor(); |
|
|||
431 | if (cursor.line === 0 && cursor.ch === 0) { |
|
|||
432 | return true; |
|
|||
433 | } else { |
|
|||
434 | return false; |
|
|||
435 | } |
|
|||
436 | }; |
|
|||
437 |
|
||||
438 |
|
||||
439 | /** @method at_bottom **/ |
|
|||
440 | RawCell.prototype.at_bottom = function () { |
|
|||
441 | var cursor = this.code_mirror.getCursor(); |
|
|||
442 | if (cursor.line === (this.code_mirror.lineCount()-1) && cursor.ch === this.code_mirror.getLine(cursor.line).length) { |
|
|||
443 | return true; |
|
|||
444 | } else { |
|
|||
445 | return false; |
|
|||
446 | } |
|
|||
447 | }; |
|
|||
448 |
|
||||
449 |
|
447 | |||
450 | /** |
|
448 | /** | |
451 | * @class HeadingCell |
|
449 | * @class HeadingCell | |
@@ -541,7 +539,8 b' var IPython = (function (IPython) {' | |||||
541 |
|
539 | |||
542 |
|
540 | |||
543 | HeadingCell.prototype.render = function () { |
|
541 | HeadingCell.prototype.render = function () { | |
544 | if (this.rendered === false) { |
|
542 | var cont = IPython.TextCell.prototype.render.apply(this); | |
|
543 | if (cont) { | |||
545 | var text = this.get_text(); |
|
544 | var text = this.get_text(); | |
546 | var math = null; |
|
545 | var math = null; | |
547 | // Markdown headings must be a single line |
|
546 | // Markdown headings must be a single line | |
@@ -567,8 +566,9 b' var IPython = (function (IPython) {' | |||||
567 | this.typeset(); |
|
566 | this.typeset(); | |
568 | this.element.find('div.text_cell_input').hide(); |
|
567 | this.element.find('div.text_cell_input').hide(); | |
569 | this.element.find("div.text_cell_render").show(); |
|
568 | this.element.find("div.text_cell_render").show(); | |
570 | this.rendered = true; |
|
569 | ||
571 | }; |
|
570 | }; | |
|
571 | return cont; | |||
572 | }; |
|
572 | }; | |
573 |
|
573 | |||
574 | IPython.TextCell = TextCell; |
|
574 | IPython.TextCell = TextCell; |
@@ -6,6 +6,14 b' div.cell {' | |||||
6 | .corner-all; |
|
6 | .corner-all; | |
7 | border : thin @border_color solid; |
|
7 | border : thin @border_color solid; | |
8 | } |
|
8 | } | |
|
9 | ||||
|
10 | &.edit_mode { | |||
|
11 | .corner-all; | |||
|
12 | border : thin green solid; | |||
|
13 | } | |||
|
14 | } | |||
|
15 | ||||
|
16 | div.cell { | |||
9 | width: 100%; |
|
17 | width: 100%; | |
10 | padding: 5px 5px 5px 0px; |
|
18 | padding: 5px 5px 5px 0px; | |
11 | /* This acts as a spacer between cells, that is outside the border */ |
|
19 | /* This acts as a spacer between cells, that is outside the border */ |
@@ -54,7 +54,9 b' input.engine_num_input{height:20px;margin-bottom:2px;padding-top:0;padding-botto' | |||||
54 | .ansibgpurple{background-color:magenta;} |
|
54 | .ansibgpurple{background-color:magenta;} | |
55 | .ansibgcyan{background-color:cyan;} |
|
55 | .ansibgcyan{background-color:cyan;} | |
56 | .ansibggray{background-color:gray;} |
|
56 | .ansibggray{background-color:gray;} | |
57 |
div.cell{border:1px solid transparent;display:-webkit-box;-webkit-box-orient:vertical;-webkit-box-align:stretch;display:-moz-box;-moz-box-orient:vertical;-moz-box-align:stretch;display:box;box-orient:vertical;box-align:stretch;width:100%; |
|
57 | div.cell{border:1px solid transparent;display:-webkit-box;-webkit-box-orient:vertical;-webkit-box-align:stretch;display:-moz-box;-moz-box-orient:vertical;-moz-box-align:stretch;display:box;box-orient:vertical;box-align:stretch;width:100%;}div.cell.selected{border-radius:4px;border:thin #ababab solid;} | |
|
58 | div.cell.edit_mode{border-radius:4px;border:thin green solid;} | |||
|
59 | div.cell{width:100%;padding:5px 5px 5px 0px;margin:0px;outline:none;} | |||
58 | div.prompt{min-width:11ex;padding:0.4em;margin:0px;font-family:monospace;text-align:right;line-height:1.231em;} |
|
60 | div.prompt{min-width:11ex;padding:0.4em;margin:0px;font-family:monospace;text-align:right;line-height:1.231em;} | |
59 | div.inner_cell{display:-webkit-box;-webkit-box-orient:vertical;-webkit-box-align:stretch;display:-moz-box;-moz-box-orient:vertical;-moz-box-align:stretch;display:box;box-orient:vertical;box-align:stretch;width:100%;-webkit-box-flex:1;-moz-box-flex:1;box-flex:1;} |
|
61 | div.inner_cell{display:-webkit-box;-webkit-box-orient:vertical;-webkit-box-align:stretch;display:-moz-box;-moz-box-orient:vertical;-moz-box-align:stretch;display:box;box-orient:vertical;box-align:stretch;width:100%;-webkit-box-flex:1;-moz-box-flex:1;box-flex:1;} | |
60 | div.prompt:empty{padding-top:0;padding-bottom:0;} |
|
62 | div.prompt:empty{padding-top:0;padding-bottom:0;} |
@@ -1435,7 +1435,9 b' input.engine_num_input{height:20px;margin-bottom:2px;padding-top:0;padding-botto' | |||||
1435 | .ansibgpurple{background-color:magenta;} |
|
1435 | .ansibgpurple{background-color:magenta;} | |
1436 | .ansibgcyan{background-color:cyan;} |
|
1436 | .ansibgcyan{background-color:cyan;} | |
1437 | .ansibggray{background-color:gray;} |
|
1437 | .ansibggray{background-color:gray;} | |
1438 |
div.cell{border:1px solid transparent;display:-webkit-box;-webkit-box-orient:vertical;-webkit-box-align:stretch;display:-moz-box;-moz-box-orient:vertical;-moz-box-align:stretch;display:box;box-orient:vertical;box-align:stretch;width:100%; |
|
1438 | div.cell{border:1px solid transparent;display:-webkit-box;-webkit-box-orient:vertical;-webkit-box-align:stretch;display:-moz-box;-moz-box-orient:vertical;-moz-box-align:stretch;display:box;box-orient:vertical;box-align:stretch;width:100%;}div.cell.selected{border-radius:4px;border:thin #ababab solid;} | |
|
1439 | div.cell.edit_mode{border-radius:4px;border:thin green solid;} | |||
|
1440 | div.cell{width:100%;padding:5px 5px 5px 0px;margin:0px;outline:none;} | |||
1439 | div.prompt{min-width:11ex;padding:0.4em;margin:0px;font-family:monospace;text-align:right;line-height:1.231em;} |
|
1441 | div.prompt{min-width:11ex;padding:0.4em;margin:0px;font-family:monospace;text-align:right;line-height:1.231em;} | |
1440 | div.inner_cell{display:-webkit-box;-webkit-box-orient:vertical;-webkit-box-align:stretch;display:-moz-box;-moz-box-orient:vertical;-moz-box-align:stretch;display:box;box-orient:vertical;box-align:stretch;width:100%;-webkit-box-flex:1;-moz-box-flex:1;box-flex:1;} |
|
1442 | div.inner_cell{display:-webkit-box;-webkit-box-orient:vertical;-webkit-box-align:stretch;display:-moz-box;-moz-box-orient:vertical;-moz-box-align:stretch;display:box;box-orient:vertical;box-align:stretch;width:100%;-webkit-box-flex:1;-moz-box-flex:1;box-flex:1;} | |
1441 | div.prompt:empty{padding-top:0;padding-bottom:0;} |
|
1443 | div.prompt:empty{padding-top:0;padding-bottom:0;} |
General Comments 0
You need to be logged in to leave comments.
Login now