mirror of
https://github.com/jupyter/notebook.git
synced 2024-12-15 04:00:34 +08:00
Merge pull request #799 from Carreau/past-and-replace
Fix and test paste_cell_replace with multi-selection
This commit is contained in:
commit
d4e467e3f4
@ -1433,20 +1433,22 @@ define(function (require) {
|
||||
* Replace the selected cell with the cells in the clipboard.
|
||||
*/
|
||||
Notebook.prototype.paste_cell_replace = function () {
|
||||
if (this.clipboard !== null && this.paste_enabled) {
|
||||
var first_inserted = null;
|
||||
for (var i=0; i < this.clipboard.length; i++) {
|
||||
var cell_data = this.clipboard;
|
||||
var new_cell = this.insert_cell_above(cell_data.cell_type);
|
||||
new_cell.fromJSON(cell_data);
|
||||
if (first_inserted === null) {
|
||||
first_inserted = new_cell;
|
||||
}
|
||||
}
|
||||
var old_selected = this.get_selected_index();
|
||||
this.select(this.find_cell_index(first_inserted));
|
||||
this.delete_cell(old_selected);
|
||||
|
||||
if (!(this.clipboard !== null && this.paste_enabled)) {
|
||||
return
|
||||
}
|
||||
|
||||
var selected = this.get_selected_cells_indices();
|
||||
var insertion_index = selected[0];
|
||||
this.delete_cells(selected);
|
||||
|
||||
for (var i=this.clipboard.length-1; i >= 0; i--) {
|
||||
var cell_data = this.clipboard[i];
|
||||
var new_cell = this.insert_cell_at_index(cell_data.cell_type, insertion_index);
|
||||
new_cell.fromJSON(cell_data);
|
||||
}
|
||||
|
||||
this.select(insertion_index+this.clipboard.length-1);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -1462,7 +1464,6 @@ define(function (require) {
|
||||
if (first_inserted === null) {
|
||||
first_inserted = new_cell;
|
||||
}
|
||||
|
||||
}
|
||||
first_inserted.focus_cell();
|
||||
}
|
||||
|
41
notebook/tests/notebook/clipboard_multiselect.js
Normal file
41
notebook/tests/notebook/clipboard_multiselect.js
Normal file
@ -0,0 +1,41 @@
|
||||
|
||||
|
||||
// Test
|
||||
casper.notebook_test(function () {
|
||||
this.append_cell('1');
|
||||
this.append_cell('2');
|
||||
this.append_cell('3');
|
||||
this.append_cell('4');
|
||||
this.append_cell('a5');
|
||||
this.append_cell('b6');
|
||||
this.append_cell('c7');
|
||||
this.append_cell('d8');
|
||||
|
||||
|
||||
|
||||
this.then(function () {
|
||||
// Copy/paste/cut
|
||||
this.select_cell(1);
|
||||
this.select_cell(3, false);
|
||||
|
||||
this.trigger_keydown('c'); // Copy
|
||||
|
||||
this.select_cell(6)
|
||||
this.select_cell(7,false)
|
||||
|
||||
this.evaluate(function () {
|
||||
$("#paste_cell_replace").click();
|
||||
});
|
||||
|
||||
var expected_state = ['', '1', '2', '3', '4', 'a5', '1' ,'2' ,'3', 'd8'];
|
||||
|
||||
for (var i=1; i<expected_state.length; i++){
|
||||
this.test.assertEquals(this.get_cell_text(i), expected_state[i],
|
||||
'Verify that cell `' + i + '` has for content: `'+ expected_state[i] + '` found : ' + this.get_cell_text(i)
|
||||
);
|
||||
}
|
||||
|
||||
this.validate_notebook_state('paste-replace', 'command', 8)
|
||||
|
||||
});
|
||||
});
|
@ -52,4 +52,4 @@ casper.notebook_test(function () {
|
||||
this.test.assertEquals(this.get_cell_text(0), c, 'Verify that cell 0 has the copied contents.');
|
||||
this.test.assertEquals(this.get_cells_length(), num_cells+3, 'Verify a the cell was added.');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user