Show More
@@ -22,6 +22,9 b' var IPython = (function (IPython) {' | |||||
22 | this.next_prompt_number = 1; |
|
22 | this.next_prompt_number = 1; | |
23 | this.kernel = null; |
|
23 | this.kernel = null; | |
24 | this.clipboard = null; |
|
24 | this.clipboard = null; | |
|
25 | this.undelete_backup = null; | |||
|
26 | this.undelete_index = null; | |||
|
27 | this.undelete_below = false; | |||
25 | this.paste_enabled = false; |
|
28 | this.paste_enabled = false; | |
26 | this.dirty = false; |
|
29 | this.dirty = false; | |
27 | this.metadata = {}; |
|
30 | this.metadata = {}; | |
@@ -257,6 +260,11 b' var IPython = (function (IPython) {' | |||||
257 | IPython.quick_help.show_keyboard_shortcuts(); |
|
260 | IPython.quick_help.show_keyboard_shortcuts(); | |
258 | that.control_key_active = false; |
|
261 | that.control_key_active = false; | |
259 | return false; |
|
262 | return false; | |
|
263 | } else if (event.which === 90 && that.control_key_active) { | |||
|
264 | // Undo last cell delete = z | |||
|
265 | that.undelete(); | |||
|
266 | that.control_key_active = false; | |||
|
267 | return false; | |||
260 | } else if (that.control_key_active) { |
|
268 | } else if (that.control_key_active) { | |
261 | that.control_key_active = false; |
|
269 | that.control_key_active = false; | |
262 | return true; |
|
270 | return true; | |
@@ -536,13 +544,19 b' var IPython = (function (IPython) {' | |||||
536 |
|
544 | |||
537 | Notebook.prototype.delete_cell = function (index) { |
|
545 | Notebook.prototype.delete_cell = function (index) { | |
538 | var i = this.index_or_selected(index); |
|
546 | var i = this.index_or_selected(index); | |
|
547 | var cell = this.get_selected_cell(); | |||
|
548 | this.undelete_backup = cell.toJSON(); | |||
539 | if (this.is_valid_cell_index(i)) { |
|
549 | if (this.is_valid_cell_index(i)) { | |
540 | var ce = this.get_cell_element(i); |
|
550 | var ce = this.get_cell_element(i); | |
541 | ce.remove(); |
|
551 | ce.remove(); | |
542 | if (i === (this.ncells())) { |
|
552 | if (i === (this.ncells())) { | |
543 | this.select(i-1); |
|
553 | this.select(i-1); | |
|
554 | this.undelete_index = i - 1; | |||
|
555 | this.undelete_below = true; | |||
544 | } else { |
|
556 | } else { | |
545 | this.select(i); |
|
557 | this.select(i); | |
|
558 | this.undelete_index = i; | |||
|
559 | this.undelete_below = false; | |||
546 | }; |
|
560 | }; | |
547 | this.dirty = true; |
|
561 | this.dirty = true; | |
548 | }; |
|
562 | }; | |
@@ -560,6 +574,11 b' var IPython = (function (IPython) {' | |||||
560 | // index = cell index or undefined to insert below selected |
|
574 | // index = cell index or undefined to insert below selected | |
561 | index = this.index_or_selected(index); |
|
575 | index = this.index_or_selected(index); | |
562 | var cell = null; |
|
576 | var cell = null; | |
|
577 | // This is intentionally < rather than <= for the sake of more | |||
|
578 | // sensible behavior in some cases. | |||
|
579 | if (this.undelete_index !== null && index < this.undelete_index) { | |||
|
580 | this.undelete_index = this.undelete_index + 1; | |||
|
581 | } | |||
563 | if (this.ncells() === 0 || this.is_valid_cell_index(index)) { |
|
582 | if (this.ncells() === 0 || this.is_valid_cell_index(index)) { | |
564 | if (type === 'code') { |
|
583 | if (type === 'code') { | |
565 | cell = new IPython.CodeCell(this.kernel); |
|
584 | cell = new IPython.CodeCell(this.kernel); | |
@@ -594,6 +613,9 b' var IPython = (function (IPython) {' | |||||
594 | // index = cell index or undefined to insert above selected |
|
613 | // index = cell index or undefined to insert above selected | |
595 | index = this.index_or_selected(index); |
|
614 | index = this.index_or_selected(index); | |
596 | var cell = null; |
|
615 | var cell = null; | |
|
616 | if (this.undelete_index !== null && index <= this.undelete_index) { | |||
|
617 | this.undelete_index = this.undelete_index + 1; | |||
|
618 | } | |||
597 | if (this.ncells() === 0 || this.is_valid_cell_index(index)) { |
|
619 | if (this.ncells() === 0 || this.is_valid_cell_index(index)) { | |
598 | if (type === 'code') { |
|
620 | if (type === 'code') { | |
599 | cell = new IPython.CodeCell(this.kernel); |
|
621 | cell = new IPython.CodeCell(this.kernel); | |
@@ -818,6 +840,33 b' var IPython = (function (IPython) {' | |||||
818 | }; |
|
840 | }; | |
819 | }; |
|
841 | }; | |
820 |
|
842 | |||
|
843 | // Cell undelete | |||
|
844 | ||||
|
845 | Notebook.prototype.undelete = function() { | |||
|
846 | if (this.undelete_backup !== null && this.undelete_index !== null) { | |||
|
847 | var current_index = this.get_selected_index(); | |||
|
848 | if (this.undelete_index < current_index) { | |||
|
849 | current_index = current_index + 1; | |||
|
850 | } | |||
|
851 | if (this.undelete_index >= this.ncells()) { | |||
|
852 | this.select(this.ncells() - 1); | |||
|
853 | } | |||
|
854 | else { | |||
|
855 | this.select(this.undelete_index); | |||
|
856 | } | |||
|
857 | var cell_data = this.undelete_backup; | |||
|
858 | var new_cell = null; | |||
|
859 | if (this.undelete_below) { | |||
|
860 | new_cell = this.insert_cell_below(cell_data.cell_type); | |||
|
861 | } else { | |||
|
862 | new_cell = this.insert_cell_above(cell_data.cell_type); | |||
|
863 | } | |||
|
864 | new_cell.fromJSON(cell_data); | |||
|
865 | this.select(current_index); | |||
|
866 | this.undelete_backup = null; | |||
|
867 | this.undelete_index = null; | |||
|
868 | } | |||
|
869 | } | |||
821 |
|
870 | |||
822 | // Split/merge |
|
871 | // Split/merge | |
823 |
|
872 |
@@ -33,6 +33,7 b' var IPython = (function (IPython) {' | |||||
33 | {key: 'Ctrl-m c', help: 'copy cell'}, |
|
33 | {key: 'Ctrl-m c', help: 'copy cell'}, | |
34 | {key: 'Ctrl-m v', help: 'paste cell'}, |
|
34 | {key: 'Ctrl-m v', help: 'paste cell'}, | |
35 | {key: 'Ctrl-m d', help: 'delete cell'}, |
|
35 | {key: 'Ctrl-m d', help: 'delete cell'}, | |
|
36 | {key: 'Ctrl-m z', help: 'undo last cell deletion'}, | |||
36 | {key: 'Ctrl-m a', help: 'insert cell above'}, |
|
37 | {key: 'Ctrl-m a', help: 'insert cell above'}, | |
37 | {key: 'Ctrl-m b', help: 'insert cell below'}, |
|
38 | {key: 'Ctrl-m b', help: 'insert cell below'}, | |
38 | {key: 'Ctrl-m o', help: 'toggle output'}, |
|
39 | {key: 'Ctrl-m o', help: 'toggle output'}, |
General Comments 0
You need to be logged in to leave comments.
Login now