mirror of
https://github.com/jupyter/notebook.git
synced 2025-03-01 12:56:54 +08:00
Run marked cells
This commit is contained in:
parent
947f08e639
commit
0fff17cdbc
@ -1976,26 +1976,48 @@ define(function (require) {
|
||||
dialog.modal(options.dialog);
|
||||
return promise;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Execute cells corresponding to the given indices.
|
||||
*
|
||||
* @param {list} indices - indices of the cells to execute
|
||||
*/
|
||||
Notebook.prototype.execute_cells = function (indices) {
|
||||
if (indices.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.command_mode();
|
||||
this.set_dirty(true);
|
||||
|
||||
var cell;
|
||||
for (var i = 0; i < indices.length; i++) {
|
||||
this.select(indices[i]);
|
||||
cell = this.get_cell(indices[i]);
|
||||
cell.execute();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Execute or render cell outputs and go into command mode.
|
||||
*/
|
||||
Notebook.prototype.execute_cell = function () {
|
||||
// mode = shift, ctrl, alt
|
||||
var cell = this.get_selected_cell();
|
||||
|
||||
cell.execute();
|
||||
this.command_mode();
|
||||
this.set_dirty(true);
|
||||
this.execute_cells(this.get_marked_indices());
|
||||
};
|
||||
|
||||
/**
|
||||
* Execute or render cell outputs and insert a new cell below.
|
||||
*/
|
||||
Notebook.prototype.execute_cell_and_insert_below = function () {
|
||||
// execute the marked cells, and don't insert anything
|
||||
var indices = this.get_marked_indices();
|
||||
if (indices.length > 1) {
|
||||
this.execute_cells(indices);
|
||||
return;
|
||||
}
|
||||
|
||||
var cell = this.get_selected_cell();
|
||||
var cell_index = this.find_cell_index(cell);
|
||||
|
||||
cell.execute();
|
||||
|
||||
// If we are at the end always insert a new cell and return
|
||||
@ -2020,10 +2042,15 @@ define(function (require) {
|
||||
* Execute or render cell outputs and select the next cell.
|
||||
*/
|
||||
Notebook.prototype.execute_cell_and_select_below = function () {
|
||||
// execute the marked cells, and don't select anything
|
||||
var indices = this.get_marked_indices();
|
||||
if (indices.length > 1) {
|
||||
this.execute_cells(indices);
|
||||
return;
|
||||
}
|
||||
|
||||
var cell = this.get_selected_cell();
|
||||
var cell_index = this.find_cell_index(cell);
|
||||
|
||||
cell.execute();
|
||||
|
||||
// If we are at the end always insert a new cell and return
|
||||
@ -2073,11 +2100,11 @@ define(function (require) {
|
||||
* @param {integer} end - index of the last cell to execute (exclusive)
|
||||
*/
|
||||
Notebook.prototype.execute_cell_range = function (start, end) {
|
||||
this.command_mode();
|
||||
var indices = [];
|
||||
for (var i=start; i<end; i++) {
|
||||
this.select(i);
|
||||
this.execute_cell();
|
||||
indices.push(i);
|
||||
}
|
||||
this.execute_cells(indices);
|
||||
};
|
||||
|
||||
// Persistance and loading
|
||||
|
@ -216,6 +216,15 @@ casper.wait_for_widget = function (widget_info) {
|
||||
});
|
||||
};
|
||||
|
||||
casper.cell_has_outputs = function (cell_num) {
|
||||
var result = casper.evaluate(function (c) {
|
||||
var cell = IPython.notebook.get_cell(c);
|
||||
return cell.output_area.outputs.length;
|
||||
},
|
||||
{c : cell_num});
|
||||
return result > 0;
|
||||
};
|
||||
|
||||
casper.get_output_cell = function (cell_num, out_num) {
|
||||
// return an output of a given cell
|
||||
out_num = out_num || 0;
|
||||
|
Loading…
Reference in New Issue
Block a user