##// END OF EJS Templates
Merge pull request #6994 from takluyver/set-next-cell-replace...
Min RK -
r19254:2d266afb merge
parent child Browse files
Show More
@@ -2003,7 +2003,7 b' class InteractiveShell(SingletonConfigurable):'
2003 continue
2003 continue
2004
2004
2005 @skip_doctest
2005 @skip_doctest
2006 def set_next_input(self, s):
2006 def set_next_input(self, s, replace=False):
2007 """ Sets the 'default' input string for the next command line.
2007 """ Sets the 'default' input string for the next command line.
2008
2008
2009 Requires readline.
2009 Requires readline.
@@ -353,7 +353,9 b' class CodeMagics(Magics):'
353 print('Operation cancelled.')
353 print('Operation cancelled.')
354 return
354 return
355
355
356 self.shell.set_next_input(contents)
356 contents = "# %load {}\n".format(arg_s) + contents
357
358 self.shell.set_next_input(contents, replace=True)
357
359
358 @staticmethod
360 @staticmethod
359 def _find_edit_target(shell, args, opts, last_call):
361 def _find_edit_target(shell, args, opts, last_call):
@@ -389,7 +389,7 b' define(['
389 * @private
389 * @private
390 */
390 */
391 CodeCell.prototype._handle_set_next_input = function (payload) {
391 CodeCell.prototype._handle_set_next_input = function (payload) {
392 var data = {'cell': this, 'text': payload.text};
392 var data = {'cell': this, 'text': payload.text, replace: payload.replace};
393 this.events.trigger('set_next_input.Notebook', data);
393 this.events.trigger('set_next_input.Notebook', data);
394 };
394 };
395
395
@@ -209,9 +209,14 b' define(['
209 var that = this;
209 var that = this;
210
210
211 this.events.on('set_next_input.Notebook', function (event, data) {
211 this.events.on('set_next_input.Notebook', function (event, data) {
212 var index = that.find_cell_index(data.cell);
212 if (data.replace) {
213 var new_cell = that.insert_cell_below('code',index);
213 data.cell.set_text(data.text);
214 new_cell.set_text(data.text);
214 data.cell.clear_output();
215 } else {
216 var index = that.find_cell_index(data.cell);
217 var new_cell = that.insert_cell_below('code',index);
218 new_cell.set_text(data.text);
219 }
215 that.dirty = true;
220 that.dirty = true;
216 });
221 });
217
222
@@ -447,12 +447,13 b' class ZMQInteractiveShell(InteractiveShell):'
447
447
448 return exc_content
448 return exc_content
449
449
450 def set_next_input(self, text):
450 def set_next_input(self, text, replace=False):
451 """Send the specified text to the frontend to be presented at the next
451 """Send the specified text to the frontend to be presented at the next
452 input cell."""
452 input cell."""
453 payload = dict(
453 payload = dict(
454 source='set_next_input',
454 source='set_next_input',
455 text=text
455 text=text,
456 replace=replace,
456 )
457 )
457 self.payload_manager.write_payload(payload)
458 self.payload_manager.write_payload(payload)
458
459
@@ -429,6 +429,9 b' The main example being ``%load``.'
429 "source": "set_next_input",
429 "source": "set_next_input",
430 # the text contents of the cell to create
430 # the text contents of the cell to create
431 "text": "some cell content",
431 "text": "some cell content",
432 # If true, replace the current cell in document UIs instead of inserting
433 # a cell. Ignored in console UIs.
434 "replace": bool,
432 }
435 }
433
436
434 **edit**: open a file for editing.
437 **edit**: open a file for editing.
General Comments 0
You need to be logged in to leave comments. Login now