Address @ellisonbg's comments

pull/597/head
Jonathan Frederic 11 years ago
parent d934ac114c
commit 0c2cc3e695

@ -423,12 +423,12 @@ define(function(require){
env.notebook.show_command_palette();
}
},
'toggle-marks': {
'toggle-cell-marked': {
help_index : 'cj',
help: 'toggle marks',
icon: 'fa-check',
handler : function(env){
env.notebook.toggle_marks(env.notebook.get_selected_cells());
env.notebook.toggle_cells_marked(env.notebook.get_selected_cells());
}
},
};

@ -93,7 +93,7 @@ define([
'enter' : 'ipython.enter-edit-mode',
'space' : 'ipython.scroll-down',
'down' : 'ipython.select-next-cell',
'ctrl-space' : 'ipython.toggle-marks',
'ctrl-space' : 'ipython.toggle-cell-marked',
'i,i' : 'ipython.interrupt-kernel',
'0,0' : 'ipython.restart-kernel',
'd,d' : 'ipython.delete-cell',

@ -401,7 +401,7 @@ define(function (require) {
var st = sme.scrollTop();
var t = sme.offset().top;
var ct = cells[index].element.offset().top;
var scroll_value = st + ct - (t + .01 * percent * h);
var scroll_value = st + ct - (t + 0.01 * percent * h);
this.scroll_manager.element.animate({scrollTop:scroll_value}, time);
return scroll_value;
};
@ -633,7 +633,7 @@ define(function (require) {
* Toggles the marks on the cells
* @param {Cell[]} [cells] - optionally specify what cells should be toggled
*/
Notebook.prototype.toggle_marks = function(cells) {
Notebook.prototype.toggle_cells_marked = function(cells) {
cells = cells || this.get_cells();
cells.forEach(function(cell) { cell.marked = !cell.marked; });
};
@ -642,7 +642,7 @@ define(function (require) {
* Mark all of the cells
* @param {Cell[]} [cells] - optionally specify what cells should be marked
*/
Notebook.prototype.mark_all = function(cells) {
Notebook.prototype.mark_all_cells = function(cells) {
cells = cells || this.get_cells();
cells.forEach(function(cell) { cell.mark(); });
};
@ -651,7 +651,7 @@ define(function (require) {
* Unmark all of the cells
* @param {Cell[]} [cells] - optionally specify what cells should be unmarked
*/
Notebook.prototype.unmark_all = function(cells) {
Notebook.prototype.unmark_all_cells = function(cells) {
this.get_marked_cells(cells).forEach(function(cell) { cell.unmark(); });
};
@ -660,8 +660,8 @@ define(function (require) {
* @param {Cell[]} cells
*/
Notebook.prototype.set_marked_cells = function(cells) {
this.unmark_all();
this.mark_all(cells);
this.unmark_all_cells();
this.mark_all_cells(cells);
};
/**
@ -681,8 +681,8 @@ define(function (require) {
*/
Notebook.prototype.set_marked_indices = function(indices, cells) {
cells = cells || this.get_cells();
this.unmark_all(cells);
this.mark_all(cells.filter(function(cell, index) { return indices.indexOf(index) !== -1; }));
this.unmark_all_cells(cells);
this.mark_all_cells(cells.filter(function(cell, index) { return indices.indexOf(index) !== -1; }));
};
/**
@ -695,6 +695,25 @@ define(function (require) {
var markedCells = this.get_marked_cells(cells);
return markedCells.map(function(cell) { return cells.indexOf(cell); });
};
/**
* Checks if the marked cells are contiguous
* @param {Cell[]} [cells] - optionally provide the cells to search through
* @return {boolean}
*/
Notebook.prototype.are_marks_contiguous = function(cells) {
// Get a numerically sorted list of the marked indices.
var markedIndices = this.get_marked_indices(cells).sort(
function(a,b) { return a-b; });
// Check for contiguousness
for (var i = 0; i < markedIndices.length - 1; i++) {
if (markedIndices[i+1] - markedIndices[i] !== 1) {
return false;
}
}
return true;
};
/**
* Get an array of the cells in the currently selected range

@ -25,6 +25,7 @@ div.cell {
&.marked {
border-left-color: blue;
border-left-width: 3px;
margin-left: -2px;
}
width: 100%;

@ -22,7 +22,7 @@ casper.notebook_test(function () {
}), 0, 'no cells are marked visibily');
this.evaluate(function() {
Jupyter.notebook.mark_all();
Jupyter.notebook.mark_all_cells();
});
var cellCount = this.evaluate(function() {
@ -38,7 +38,7 @@ casper.notebook_test(function () {
}), cellCount, 'marked cells are marked visibily');
this.evaluate(function() {
Jupyter.notebook.unmark_all();
Jupyter.notebook.unmark_all_cells();
});
this.test.assertEquals(this.evaluate(function() {

Loading…
Cancel
Save