##// END OF EJS Templates
Merge pull request #5882 from ivanov/preserve-cell-type...
Min RK -
r16782:dfe8be37 merge
parent child Browse files
Show More
@@ -259,7 +259,7 b' var IPython = (function (IPython) {'
259 259 help : 'insert cell above',
260 260 help_index : 'ec',
261 261 handler : function (event) {
262 IPython.notebook.insert_cell_above('code');
262 IPython.notebook.insert_cell_above();
263 263 IPython.notebook.select_prev();
264 264 IPython.notebook.focus_cell();
265 265 return false;
@@ -269,7 +269,7 b' var IPython = (function (IPython) {'
269 269 help : 'insert cell below',
270 270 help_index : 'ed',
271 271 handler : function (event) {
272 IPython.notebook.insert_cell_below('code');
272 IPython.notebook.insert_cell_below();
273 273 IPython.notebook.select_next();
274 274 IPython.notebook.focus_cell();
275 275 return false;
@@ -731,13 +731,16 b' var IPython = (function (IPython) {'
731 731 /**
732 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 737 * Similar to insert_above, but index parameter is mandatory
735 738 *
736 * Index will be brought back into the accissible range [0,n]
739 * Index will be brought back into the accessible range [0,n]
737 740 *
738 741 * @method insert_cell_at_index
739 * @param type {string} in ['code','markdown','heading']
740 * @param [index] {int} a valid index where to inser cell
742 * @param [type] {string} in ['code','markdown','heading'], defaults to 'code'
743 * @param [index] {int} a valid index where to insert cell
741 744 *
742 745 * @return cell {cell|null} created cell or null
743 746 **/
@@ -747,6 +750,7 b' var IPython = (function (IPython) {'
747 750 index = Math.min(index,ncells);
748 751 index = Math.max(index,0);
749 752 var cell = null;
753 type = type || this.get_selected_cell().cell_type;
750 754
751 755 if (ncells === 0 || this.is_valid_cell_index(index) || index === ncells) {
752 756 if (type === 'code') {
@@ -819,7 +823,7 b' var IPython = (function (IPython) {'
819 823 * default index value is the one of currently selected cell
820 824 *
821 825 * @method insert_cell_above
822 * @param type {string} cell type
826 * @param [type] {string} cell type
823 827 * @param [index] {integer}
824 828 *
825 829 * @return handle to created cell or null
@@ -831,12 +835,12 b' var IPython = (function (IPython) {'
831 835
832 836 /**
833 837 * Insert a cell of given type below given index, or at bottom
834 * of notebook if index greater thatn number of cell
838 * of notebook if index greater than number of cells
835 839 *
836 840 * default index value is the one of currently selected cell
837 841 *
838 842 * @method insert_cell_below
839 * @param type {string} cell type
843 * @param [type] {string} cell type
840 844 * @param [index] {integer}
841 845 *
842 846 * @return handle to created cell or null
@@ -1474,7 +1478,7 b' var IPython = (function (IPython) {'
1474 1478 // If we are at the end always insert a new cell and return
1475 1479 if (cell_index === (this.ncells()-1)) {
1476 1480 this.command_mode();
1477 this.insert_cell_below('code');
1481 this.insert_cell_below();
1478 1482 this.select(cell_index+1);
1479 1483 this.edit_mode();
1480 1484 this.scroll_to_bottom();
@@ -1483,7 +1487,7 b' var IPython = (function (IPython) {'
1483 1487 }
1484 1488
1485 1489 this.command_mode();
1486 this.insert_cell_below('code');
1490 this.insert_cell_below();
1487 1491 this.select(cell_index+1);
1488 1492 this.edit_mode();
1489 1493 this.set_dirty(true);
@@ -1504,7 +1508,7 b' var IPython = (function (IPython) {'
1504 1508 // If we are at the end always insert a new cell and return
1505 1509 if (cell_index === (this.ncells()-1)) {
1506 1510 this.command_mode();
1507 this.insert_cell_below('code');
1511 this.insert_cell_below();
1508 1512 this.select(cell_index+1);
1509 1513 this.edit_mode();
1510 1514 this.scroll_to_bottom();
@@ -18,10 +18,25 b' casper.notebook_test(function () {'
18 18 this.select_cell(2);
19 19 this.trigger_keydown('a'); // Creates one cell
20 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 22 this.validate_notebook_state('a', 'command', 2);
22 23 this.trigger_keydown('b'); // Creates one cell
23 24 this.test.assertEquals(this.get_cell_text(2), '', 'b; Cell 2 text is still empty');
24 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 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 167 casper.insert_cell_at_bottom = function(cell_type){
168 168 // Inserts a cell at the bottom of the notebook
169 169 // Returns the new cell's index.
170 cell_type = cell_type || 'code';
171
172 170 return this.evaluate(function (cell_type) {
173 171 var cell = IPython.notebook.insert_cell_at_bottom(cell_type);
174 172 return IPython.notebook.find_cell_index(cell);
General Comments 0
You need to be logged in to leave comments. Login now