Show More
@@ -53,7 +53,7 define([ | |||
|
53 | 53 | // base_url : string |
|
54 | 54 | // notebook_path : string |
|
55 | 55 | // notebook_name : string |
|
56 |
this.config = options.config |
|
|
56 | this.config = utils.mergeopt(Notebook, options.config); | |
|
57 | 57 | this.base_url = options.base_url; |
|
58 | 58 | this.notebook_path = options.notebook_path; |
|
59 | 59 | this.notebook_name = options.notebook_name; |
@@ -63,6 +63,7 define([ | |||
|
63 | 63 | this.tooltip = new tooltip.Tooltip(this.events); |
|
64 | 64 | this.ws_url = options.ws_url; |
|
65 | 65 | this._session_starting = false; |
|
66 | this.default_cell_type = this.config.default_cell_type || 'code'; | |
|
66 | 67 | // default_kernel_name is a temporary measure while we implement proper |
|
67 | 68 | // kernel selection and delayed start. Do not rely on it. |
|
68 | 69 | this.default_kernel_name = 'python'; |
@@ -134,6 +135,14 define([ | |||
|
134 | 135 | rawcell_celltoolbar.register(this); |
|
135 | 136 | slideshow_celltoolbar.register(this); |
|
136 | 137 | }; |
|
138 | ||
|
139 | Notebook.options_default = { | |
|
140 | // can be any cell type, or the special values of | |
|
141 | // 'above', 'below', or 'selected' to get the value from another cell. | |
|
142 | Notebook: { | |
|
143 | default_cell_type: 'code', | |
|
144 | } | |
|
145 | }; | |
|
137 | 146 | |
|
138 | 147 | |
|
139 | 148 | /** |
@@ -835,10 +844,25 define([ | |||
|
835 | 844 | Notebook.prototype.insert_cell_at_index = function(type, index){ |
|
836 | 845 | |
|
837 | 846 | var ncells = this.ncells(); |
|
838 | index = Math.min(index,ncells); | |
|
839 | index = Math.max(index,0); | |
|
847 | index = Math.min(index, ncells); | |
|
848 | index = Math.max(index, 0); | |
|
840 | 849 | var cell = null; |
|
841 |
type = type || this. |
|
|
850 | type = type || this.default_cell_type; | |
|
851 | if (type === 'above') { | |
|
852 | if (index > 0) { | |
|
853 | type = this.get_cell(index-1).cell_type; | |
|
854 | } else { | |
|
855 | type = 'code'; | |
|
856 | } | |
|
857 | } else if (type === 'below') { | |
|
858 | if (index < ncells) { | |
|
859 | type = this.get_cell(index).cell_type; | |
|
860 | } else { | |
|
861 | type = 'code'; | |
|
862 | } | |
|
863 | } else if (type === 'selected') { | |
|
864 | type = this.get_selected_cell().cell_type; | |
|
865 | } | |
|
842 | 866 | |
|
843 | 867 | if (ncells === 0 || this.is_valid_cell_index(index) || index === ncells) { |
|
844 | 868 | var cell_options = { |
@@ -12,31 +12,66 casper.notebook_test(function () { | |||
|
12 | 12 | var c = 'print("c")'; |
|
13 | 13 | index = this.append_cell(c); |
|
14 | 14 | this.execute_cell_then(index); |
|
15 | ||
|
15 | ||
|
16 | this.thenEvaluate(function() { | |
|
17 | IPython.notebook.default_cell_type = 'code'; | |
|
18 | }); | |
|
19 | ||
|
16 | 20 | this.then(function () { |
|
17 | 21 | // Cell insertion |
|
18 | 22 | this.select_cell(2); |
|
23 | this.trigger_keydown('m'); // Make it markdown | |
|
19 | 24 | this.trigger_keydown('a'); // Creates one cell |
|
20 | 25 | 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 |
|
|
26 | this.test.assertEquals(this.get_cell(2).cell_type, 'code', 'a; inserts a code cell'); | |
|
22 | 27 | this.validate_notebook_state('a', 'command', 2); |
|
23 | 28 | this.trigger_keydown('b'); // Creates one cell |
|
24 | 29 | this.test.assertEquals(this.get_cell_text(2), '', 'b; Cell 2 text is still empty'); |
|
25 | 30 | 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 |
|
|
31 | this.test.assertEquals(this.get_cell(3).cell_type, 'code', 'b; inserts a code cell'); | |
|
27 | 32 | this.validate_notebook_state('b', 'command', 3); |
|
28 | 33 | }); |
|
34 | ||
|
35 | this.thenEvaluate(function() { | |
|
36 | IPython.notebook.default_cell_type = 'selected'; | |
|
37 | }); | |
|
38 | ||
|
29 | 39 | this.then(function () { |
|
30 | // Cell insertion | |
|
31 | 40 | this.select_cell(2); |
|
32 | 41 | 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 |
|
|
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); | |
|
42 | this.test.assertEquals(this.get_cell(2).cell_type, 'markdown', 'test cell is markdown'); | |
|
43 | this.trigger_keydown('a'); // new cell above | |
|
44 | this.test.assertEquals(this.get_cell(2).cell_type, 'markdown', 'a; inserts a markdown cell when markdown selected'); | |
|
45 | this.trigger_keydown('b'); // new cell below | |
|
46 | this.test.assertEquals(this.get_cell(3).cell_type, 'markdown', 'b; inserts a markdown cell when markdown selected'); | |
|
47 | }); | |
|
48 | ||
|
49 | this.thenEvaluate(function() { | |
|
50 | IPython.notebook.default_cell_type = 'above'; | |
|
51 | }); | |
|
52 | ||
|
53 | this.then(function () { | |
|
54 | this.select_cell(2); | |
|
55 | this.trigger_keydown('1'); // switch it to heading for the next test | |
|
56 | this.test.assertEquals(this.get_cell(2).cell_type, 'heading', 'test cell is heading'); | |
|
57 | this.trigger_keydown('b'); // new cell below | |
|
58 | this.test.assertEquals(this.get_cell(3).cell_type, 'heading', 'b; inserts a heading cell below heading cell'); | |
|
59 | this.trigger_keydown('a'); // new cell above | |
|
60 | this.test.assertEquals(this.get_cell(3).cell_type, 'heading', 'a; inserts a heading cell below heading cell'); | |
|
61 | }); | |
|
62 | ||
|
63 | this.thenEvaluate(function() { | |
|
64 | IPython.notebook.default_cell_type = 'below'; | |
|
65 | }); | |
|
66 | ||
|
67 | this.then(function () { | |
|
68 | this.select_cell(2); | |
|
69 | this.trigger_keydown('r'); // switch it to markdown for the next test | |
|
70 | this.test.assertEquals(this.get_cell(2).cell_type, 'raw', 'test cell is raw'); | |
|
71 | this.trigger_keydown('a'); // new cell above | |
|
72 | this.test.assertEquals(this.get_cell(2).cell_type, 'raw', 'a; inserts a raw cell above raw cell'); | |
|
73 | this.trigger_keydown('y'); // switch it to code for the next test | |
|
74 | this.trigger_keydown('b'); // new cell below | |
|
75 | this.test.assertEquals(this.get_cell(3).cell_type, 'raw', 'b; inserts a raw cell above raw cell'); | |
|
41 | 76 | }); |
|
42 | 77 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now