##// END OF EJS Templates
Machinery to replace the current cell instead of adding a new one
Thomas Kluyver -
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.
@@ -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,13 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 } else {
215 var index = that.find_cell_index(data.cell);
216 var new_cell = that.insert_cell_below('code',index);
217 new_cell.set_text(data.text);
218 }
215 that.dirty = true;
219 that.dirty = true;
216 });
220 });
217
221
@@ -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
General Comments 0
You need to be logged in to leave comments. Login now