Show More
@@ -259,7 +259,7 b' var IPython = (function (IPython) {' | |||||
259 | help : 'insert cell above', |
|
259 | help : 'insert cell above', | |
260 | help_index : 'ec', |
|
260 | help_index : 'ec', | |
261 | handler : function (event) { |
|
261 | handler : function (event) { | |
262 |
IPython.notebook.insert_cell_above( |
|
262 | IPython.notebook.insert_cell_above(); | |
263 | IPython.notebook.select_prev(); |
|
263 | IPython.notebook.select_prev(); | |
264 | IPython.notebook.focus_cell(); |
|
264 | IPython.notebook.focus_cell(); | |
265 | return false; |
|
265 | return false; | |
@@ -269,7 +269,7 b' var IPython = (function (IPython) {' | |||||
269 | help : 'insert cell below', |
|
269 | help : 'insert cell below', | |
270 | help_index : 'ed', |
|
270 | help_index : 'ed', | |
271 | handler : function (event) { |
|
271 | handler : function (event) { | |
272 |
IPython.notebook.insert_cell_below( |
|
272 | IPython.notebook.insert_cell_below(); | |
273 | IPython.notebook.select_next(); |
|
273 | IPython.notebook.select_next(); | |
274 | IPython.notebook.focus_cell(); |
|
274 | IPython.notebook.focus_cell(); | |
275 | return false; |
|
275 | return false; |
@@ -731,13 +731,16 b' var IPython = (function (IPython) {' | |||||
731 | /** |
|
731 | /** | |
732 | * Insert a cell so that after insertion the cell is at given index. |
|
732 | * Insert a cell so that after insertion the cell is at given index. | |
733 | * |
|
733 | * | |
|
734 | * If cell type is not provided, it will default to the type of the | |||
|
735 | * currently active cell. | |||
|
736 | * | |||
734 | * Similar to insert_above, but index parameter is mandatory |
|
737 | * Similar to insert_above, but index parameter is mandatory | |
735 | * |
|
738 | * | |
736 |
* Index will be brought back into the acc |
|
739 | * Index will be brought back into the accessible range [0,n] | |
737 | * |
|
740 | * | |
738 | * @method insert_cell_at_index |
|
741 | * @method insert_cell_at_index | |
739 | * @param type {string} in ['code','markdown','heading'] |
|
742 | * @param [type] {string} in ['code','markdown','heading'], defaults to 'code' | |
740 | * @param [index] {int} a valid index where to inser cell |
|
743 | * @param [index] {int} a valid index where to insert cell | |
741 | * |
|
744 | * | |
742 | * @return cell {cell|null} created cell or null |
|
745 | * @return cell {cell|null} created cell or null | |
743 | **/ |
|
746 | **/ | |
@@ -747,6 +750,7 b' var IPython = (function (IPython) {' | |||||
747 | index = Math.min(index,ncells); |
|
750 | index = Math.min(index,ncells); | |
748 | index = Math.max(index,0); |
|
751 | index = Math.max(index,0); | |
749 | var cell = null; |
|
752 | var cell = null; | |
|
753 | type = type || this.get_selected_cell().cell_type; | |||
750 |
|
754 | |||
751 | if (ncells === 0 || this.is_valid_cell_index(index) || index === ncells) { |
|
755 | if (ncells === 0 || this.is_valid_cell_index(index) || index === ncells) { | |
752 | if (type === 'code') { |
|
756 | if (type === 'code') { | |
@@ -819,7 +823,7 b' var IPython = (function (IPython) {' | |||||
819 | * default index value is the one of currently selected cell |
|
823 | * default index value is the one of currently selected cell | |
820 | * |
|
824 | * | |
821 | * @method insert_cell_above |
|
825 | * @method insert_cell_above | |
822 | * @param type {string} cell type |
|
826 | * @param [type] {string} cell type | |
823 | * @param [index] {integer} |
|
827 | * @param [index] {integer} | |
824 | * |
|
828 | * | |
825 | * @return handle to created cell or null |
|
829 | * @return handle to created cell or null | |
@@ -831,12 +835,12 b' var IPython = (function (IPython) {' | |||||
831 |
|
835 | |||
832 | /** |
|
836 | /** | |
833 | * Insert a cell of given type below given index, or at bottom |
|
837 | * Insert a cell of given type below given index, or at bottom | |
834 |
* of notebook if index greater tha |
|
838 | * of notebook if index greater than number of cells | |
835 | * |
|
839 | * | |
836 | * default index value is the one of currently selected cell |
|
840 | * default index value is the one of currently selected cell | |
837 | * |
|
841 | * | |
838 | * @method insert_cell_below |
|
842 | * @method insert_cell_below | |
839 | * @param type {string} cell type |
|
843 | * @param [type] {string} cell type | |
840 | * @param [index] {integer} |
|
844 | * @param [index] {integer} | |
841 | * |
|
845 | * | |
842 | * @return handle to created cell or null |
|
846 | * @return handle to created cell or null | |
@@ -1474,7 +1478,7 b' var IPython = (function (IPython) {' | |||||
1474 | // If we are at the end always insert a new cell and return |
|
1478 | // If we are at the end always insert a new cell and return | |
1475 | if (cell_index === (this.ncells()-1)) { |
|
1479 | if (cell_index === (this.ncells()-1)) { | |
1476 | this.command_mode(); |
|
1480 | this.command_mode(); | |
1477 |
this.insert_cell_below( |
|
1481 | this.insert_cell_below(); | |
1478 | this.select(cell_index+1); |
|
1482 | this.select(cell_index+1); | |
1479 | this.edit_mode(); |
|
1483 | this.edit_mode(); | |
1480 | this.scroll_to_bottom(); |
|
1484 | this.scroll_to_bottom(); | |
@@ -1483,7 +1487,7 b' var IPython = (function (IPython) {' | |||||
1483 | } |
|
1487 | } | |
1484 |
|
1488 | |||
1485 | this.command_mode(); |
|
1489 | this.command_mode(); | |
1486 |
this.insert_cell_below( |
|
1490 | this.insert_cell_below(); | |
1487 | this.select(cell_index+1); |
|
1491 | this.select(cell_index+1); | |
1488 | this.edit_mode(); |
|
1492 | this.edit_mode(); | |
1489 | this.set_dirty(true); |
|
1493 | this.set_dirty(true); | |
@@ -1504,7 +1508,7 b' var IPython = (function (IPython) {' | |||||
1504 | // If we are at the end always insert a new cell and return |
|
1508 | // If we are at the end always insert a new cell and return | |
1505 | if (cell_index === (this.ncells()-1)) { |
|
1509 | if (cell_index === (this.ncells()-1)) { | |
1506 | this.command_mode(); |
|
1510 | this.command_mode(); | |
1507 |
this.insert_cell_below( |
|
1511 | this.insert_cell_below(); | |
1508 | this.select(cell_index+1); |
|
1512 | this.select(cell_index+1); | |
1509 | this.edit_mode(); |
|
1513 | this.edit_mode(); | |
1510 | this.scroll_to_bottom(); |
|
1514 | this.scroll_to_bottom(); |
@@ -18,10 +18,25 b' casper.notebook_test(function () {' | |||||
18 | this.select_cell(2); |
|
18 | this.select_cell(2); | |
19 | this.trigger_keydown('a'); // Creates one cell |
|
19 | this.trigger_keydown('a'); // Creates one cell | |
20 | this.test.assertEquals(this.get_cell_text(2), '', 'a; New cell 2 text is empty'); |
|
20 | this.test.assertEquals(this.get_cell_text(2), '', 'a; New cell 2 text is empty'); | |
|
21 | this.test.assertEquals(this.get_cell(2).cell_type, 'code', 'a; inserts a code cell when on code cell'); | |||
21 | this.validate_notebook_state('a', 'command', 2); |
|
22 | this.validate_notebook_state('a', 'command', 2); | |
22 | this.trigger_keydown('b'); // Creates one cell |
|
23 | this.trigger_keydown('b'); // Creates one cell | |
23 | this.test.assertEquals(this.get_cell_text(2), '', 'b; Cell 2 text is still empty'); |
|
24 | this.test.assertEquals(this.get_cell_text(2), '', 'b; Cell 2 text is still empty'); | |
24 | this.test.assertEquals(this.get_cell_text(3), '', 'b; New cell 3 text is empty'); |
|
25 | this.test.assertEquals(this.get_cell_text(3), '', 'b; New cell 3 text is empty'); | |
|
26 | this.test.assertEquals(this.get_cell(3).cell_type, 'code', 'b; inserts a code cell when on code cell'); | |||
25 | this.validate_notebook_state('b', 'command', 3); |
|
27 | this.validate_notebook_state('b', 'command', 3); | |
26 | }); |
|
28 | }); | |
27 | }); No newline at end of file |
|
29 | this.then(function () { | |
|
30 | // Cell insertion | |||
|
31 | this.select_cell(2); | |||
|
32 | this.trigger_keydown('m'); // switch it to markdown for the next test | |||
|
33 | this.trigger_keydown('a'); // Creates one cell | |||
|
34 | this.test.assertEquals(this.get_cell_text(2), '', 'a; New cell 2 text is empty'); | |||
|
35 | this.test.assertEquals(this.get_cell(2).cell_type, 'markdown', 'a; inserts a markdown cell when on markdown cell'); | |||
|
36 | this.validate_notebook_state('a', 'command', 2); | |||
|
37 | this.trigger_keydown('b'); // Creates one cell | |||
|
38 | this.test.assertEquals(this.get_cell_text(2), '', 'b; Cell 2 text is still empty'); | |||
|
39 | this.test.assertEquals(this.get_cell(3).cell_type, 'markdown', 'b; inserts a markdown cell when on markdown cell'); | |||
|
40 | this.validate_notebook_state('b', 'command', 3); | |||
|
41 | }); | |||
|
42 | }); |
@@ -167,8 +167,6 b' casper.get_cell_text = function(index){' | |||||
167 | casper.insert_cell_at_bottom = function(cell_type){ |
|
167 | casper.insert_cell_at_bottom = function(cell_type){ | |
168 | // Inserts a cell at the bottom of the notebook |
|
168 | // Inserts a cell at the bottom of the notebook | |
169 | // Returns the new cell's index. |
|
169 | // Returns the new cell's index. | |
170 | cell_type = cell_type || 'code'; |
|
|||
171 |
|
||||
172 | return this.evaluate(function (cell_type) { |
|
170 | return this.evaluate(function (cell_type) { | |
173 | var cell = IPython.notebook.insert_cell_at_bottom(cell_type); |
|
171 | var cell = IPython.notebook.insert_cell_at_bottom(cell_type); | |
174 | return IPython.notebook.find_cell_index(cell); |
|
172 | return IPython.notebook.find_cell_index(cell); |
General Comments 0
You need to be logged in to leave comments.
Login now