##// END OF EJS Templates
Fixing delete/undelete logic.
Brian E. Granger -
Show More
@@ -239,7 +239,7 var IPython = (function (IPython) {
239 239 return false;
240 240 } else if (event.which === 90) {
241 241 // Undo last cell delete = z
242 notebook.undelete();
242 notebook.undelete_cell();
243 243 return false;
244 244 } else if (event.which === 189 || event.which === 173) {
245 245 // how fun! '-' is 189 in Chrome, but 173 in FF and Opera
@@ -161,7 +161,7 var IPython = (function (IPython) {
161 161 IPython.notebook.delete_cell();
162 162 });
163 163 this.element.find('#undelete_cell').click(function () {
164 IPython.notebook.undelete();
164 IPython.notebook.undelete_cell();
165 165 });
166 166 this.element.find('#split_cell').click(function () {
167 167 IPython.notebook.split_cell();
@@ -615,9 +615,18 var IPython = (function (IPython) {
615 615 this.undelete_backup = cell.toJSON();
616 616 $('#undelete_cell').removeClass('disabled');
617 617 if (this.is_valid_cell_index(i)) {
618 var old_ncells = this.ncells();
618 619 var ce = this.get_cell_element(i);
619 620 ce.remove();
620 if (i === (this.ncells())) {
621 if (i === 0) {
622 // Always make sure we have at least one cell.
623 if (old_ncells === 1) {
624 this.insert_cell_below('code');
625 }
626 this.select(0);
627 this.undelete_index = 0;
628 this.undelete_below = false;
629 } else if (i === old_ncells-1 && i !== 0) {
621 630 this.select(i-1);
622 631 this.undelete_index = i - 1;
623 632 this.undelete_below = true;
@@ -633,6 +642,42 var IPython = (function (IPython) {
633 642 };
634 643
635 644 /**
645 * Restore the most recently deleted cell.
646 *
647 * @method undelete
648 */
649 Notebook.prototype.undelete_cell = function() {
650 if (this.undelete_backup !== null && this.undelete_index !== null) {
651 var current_index = this.get_selected_index();
652 if (this.undelete_index < current_index) {
653 current_index = current_index + 1;
654 }
655 if (this.undelete_index >= this.ncells()) {
656 this.select(this.ncells() - 1);
657 }
658 else {
659 this.select(this.undelete_index);
660 }
661 var cell_data = this.undelete_backup;
662 var new_cell = null;
663 if (this.undelete_below) {
664 new_cell = this.insert_cell_below(cell_data.cell_type);
665 } else {
666 new_cell = this.insert_cell_above(cell_data.cell_type);
667 }
668 new_cell.fromJSON(cell_data);
669 if (this.undelete_below) {
670 this.select(current_index+1);
671 } else {
672 this.select(current_index);
673 }
674 this.undelete_backup = null;
675 this.undelete_index = null;
676 }
677 $('#undelete_cell').addClass('disabled');
678 }
679
680 /**
636 681 * Insert a cell so that after insertion the cell is at given index.
637 682 *
638 683 * Similar to insert_above, but index parameter is mandatory
@@ -995,40 +1040,6 var IPython = (function (IPython) {
995 1040 };
996 1041 };
997 1042
998 // Cell undelete
999
1000 /**
1001 * Restore the most recently deleted cell.
1002 *
1003 * @method undelete
1004 */
1005 Notebook.prototype.undelete = function() {
1006 if (this.undelete_backup !== null && this.undelete_index !== null) {
1007 var current_index = this.get_selected_index();
1008 if (this.undelete_index < current_index) {
1009 current_index = current_index + 1;
1010 }
1011 if (this.undelete_index >= this.ncells()) {
1012 this.select(this.ncells() - 1);
1013 }
1014 else {
1015 this.select(this.undelete_index);
1016 }
1017 var cell_data = this.undelete_backup;
1018 var new_cell = null;
1019 if (this.undelete_below) {
1020 new_cell = this.insert_cell_below(cell_data.cell_type);
1021 } else {
1022 new_cell = this.insert_cell_above(cell_data.cell_type);
1023 }
1024 new_cell.fromJSON(cell_data);
1025 this.select(current_index);
1026 this.undelete_backup = null;
1027 this.undelete_index = null;
1028 }
1029 $('#undelete_cell').addClass('disabled');
1030 }
1031
1032 1043 // Split/merge
1033 1044
1034 1045 /**
General Comments 0
You need to be logged in to leave comments. Login now