mirror of
https://github.com/jupyter/notebook.git
synced 2025-03-07 13:07:22 +08:00
Merge pull request #676 from jhamrick/mark-behavior
Minor changes to marking behavior
This commit is contained in:
commit
947f08e639
@ -664,7 +664,7 @@ define(function (require) {
|
||||
*/
|
||||
Notebook.prototype.get_marked_cells = function(cells) {
|
||||
cells = cells || this.get_cells();
|
||||
return cells.filter(function(cell) { return cell.marked; });
|
||||
return cells.filter(function(cell) { return (cell.marked || cell.selected); });
|
||||
};
|
||||
|
||||
/**
|
||||
@ -727,16 +727,13 @@ define(function (require) {
|
||||
* @param {number} offset
|
||||
*/
|
||||
Notebook.prototype.extend_marked = function(offset) {
|
||||
|
||||
// Mark currently selected cell
|
||||
this.get_selected_cell().marked = true;
|
||||
|
||||
|
||||
// Select the cell in the offset direction. Bound index between 0 and
|
||||
// the number of cells -1.
|
||||
var selectedIndex = Math.min(Math.max(this.get_selected_index() + offset, 0), this.ncells()-1);
|
||||
this.select(selectedIndex);
|
||||
this.get_selected_cell().marked = true;
|
||||
|
||||
this.ensure_focused();
|
||||
};
|
||||
|
||||
@ -981,10 +978,6 @@ define(function (require) {
|
||||
Notebook.prototype.delete_cells = function(indices) {
|
||||
if (indices === undefined) {
|
||||
indices = this.get_marked_indices();
|
||||
|
||||
if (indices.length === 0) {
|
||||
indices = [this.get_selected_index()];
|
||||
}
|
||||
}
|
||||
|
||||
this.undelete_backup = [];
|
||||
@ -1563,6 +1556,7 @@ define(function (require) {
|
||||
this.delete_cells(indices);
|
||||
|
||||
this.select(this.find_cell_index(target));
|
||||
this.unmark_all_cells();
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -13,10 +13,19 @@ casper.notebook_test(function () {
|
||||
index = this.append_cell(c);
|
||||
|
||||
this.then(function () {
|
||||
var selectedIndex = this.evaluate(function () {
|
||||
Jupyter.notebook.select(0);
|
||||
return Jupyter.notebook.get_selected_index();
|
||||
});
|
||||
|
||||
this.test.assertEquals(this.evaluate(function() {
|
||||
return Jupyter.notebook.get_marked_cells().length;
|
||||
}), 0, 'no cells are marked programmatically');
|
||||
|
||||
}), 1, 'only one cell is marked programmatically');
|
||||
|
||||
this.test.assertEquals(this.evaluate(function() {
|
||||
return Jupyter.notebook.get_marked_indices()[0];
|
||||
}), selectedIndex, 'marked cell is selected cell');
|
||||
|
||||
this.test.assertEquals(this.evaluate(function() {
|
||||
return $('.cell.marked').length;
|
||||
}), 0, 'no cells are marked visibily');
|
||||
@ -43,14 +52,22 @@ casper.notebook_test(function () {
|
||||
|
||||
this.test.assertEquals(this.evaluate(function() {
|
||||
return Jupyter.notebook.get_marked_cells().length;
|
||||
}), 0, 'unmark_all');
|
||||
|
||||
}), 1, 'unmark_all');
|
||||
|
||||
this.test.assertEquals(this.evaluate(function() {
|
||||
return Jupyter.notebook.get_marked_indices()[0];
|
||||
}), selectedIndex, 'marked cell is selected cell');
|
||||
|
||||
this.evaluate(function() {
|
||||
Jupyter.notebook.set_marked_indices([1]);
|
||||
});
|
||||
|
||||
this.test.assertEquals(this.evaluate(function() {
|
||||
return Jupyter.notebook.get_marked_indices()[0];
|
||||
}), 1, 'get/set_marked_indices');
|
||||
|
||||
this.test.assertEquals(this.evaluate(function() {
|
||||
return Jupyter.notebook.get_marked_cells().length;
|
||||
}), 2, 'two cells are marked');
|
||||
|
||||
this.test.assertEquals(this.evaluate(function() {
|
||||
return Jupyter.notebook.get_marked_indices();
|
||||
}), [selectedIndex, 1], 'get/set_marked_indices');
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user