mirror of
https://github.com/jupyter/notebook.git
synced 2025-03-13 13:17:50 +08:00
Make past and replace actually replace selection.
It used to replace only the head of the selection. Change tests accordingly
This commit is contained in:
parent
57b9550b8d
commit
a863916505
@ -1380,20 +1380,23 @@ 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[i];
|
||||
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--) {
|
||||
debugger;
|
||||
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);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -1409,7 +1412,6 @@ define(function (require) {
|
||||
if (first_inserted === null) {
|
||||
first_inserted = new_cell;
|
||||
}
|
||||
|
||||
}
|
||||
first_inserted.focus_cell();
|
||||
}
|
||||
|
@ -5,27 +5,29 @@ casper.notebook_test(function () {
|
||||
this.append_cell('1');
|
||||
this.append_cell('2');
|
||||
this.append_cell('3');
|
||||
this.append_cell('a');
|
||||
this.append_cell('b');
|
||||
this.append_cell('c');
|
||||
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
|
||||
var num_cells = this.get_cells_length();
|
||||
this.test.assertEquals(this.get_cell_text(1), '1', 'YOUUUUUU Verify that cell 1 is a');
|
||||
this.select_cell(1);
|
||||
this.select_cell(3, false);
|
||||
|
||||
this.trigger_keydown('c'); // Copy
|
||||
|
||||
this.select_cell(5)
|
||||
this.select_cell(6)
|
||||
this.select_cell(7,false)
|
||||
|
||||
this.evaluate(function () {
|
||||
$("#paste_cell_replace").click();
|
||||
});
|
||||
|
||||
var expected_state = ['','1','2','3', 'a', '1', '2', '3', 'c'];
|
||||
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],
|
||||
|
Loading…
x
Reference in New Issue
Block a user