Show More
@@ -53,7 +53,7 define([ | |||||
53 | // base_url : string |
|
53 | // base_url : string | |
54 | // notebook_path : string |
|
54 | // notebook_path : string | |
55 | // notebook_name : string |
|
55 | // notebook_name : string | |
56 |
this.config = options.config |
|
56 | this.config = utils.mergeopt(Notebook, options.config); | |
57 | this.base_url = options.base_url; |
|
57 | this.base_url = options.base_url; | |
58 | this.notebook_path = options.notebook_path; |
|
58 | this.notebook_path = options.notebook_path; | |
59 | this.notebook_name = options.notebook_name; |
|
59 | this.notebook_name = options.notebook_name; | |
@@ -63,6 +63,7 define([ | |||||
63 | this.tooltip = new tooltip.Tooltip(this.events); |
|
63 | this.tooltip = new tooltip.Tooltip(this.events); | |
64 | this.ws_url = options.ws_url; |
|
64 | this.ws_url = options.ws_url; | |
65 | this._session_starting = false; |
|
65 | this._session_starting = false; | |
|
66 | this.default_cell_type = this.config.default_cell_type || 'code'; | |||
66 | // default_kernel_name is a temporary measure while we implement proper |
|
67 | // default_kernel_name is a temporary measure while we implement proper | |
67 | // kernel selection and delayed start. Do not rely on it. |
|
68 | // kernel selection and delayed start. Do not rely on it. | |
68 | this.default_kernel_name = 'python'; |
|
69 | this.default_kernel_name = 'python'; | |
@@ -134,6 +135,14 define([ | |||||
134 | rawcell_celltoolbar.register(this); |
|
135 | rawcell_celltoolbar.register(this); | |
135 | slideshow_celltoolbar.register(this); |
|
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 | Notebook.prototype.insert_cell_at_index = function(type, index){ |
|
844 | Notebook.prototype.insert_cell_at_index = function(type, index){ | |
836 |
|
845 | |||
837 | var ncells = this.ncells(); |
|
846 | var ncells = this.ncells(); | |
838 | index = Math.min(index,ncells); |
|
847 | index = Math.min(index, ncells); | |
839 | index = Math.max(index,0); |
|
848 | index = Math.max(index, 0); | |
840 | var cell = null; |
|
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 | if (ncells === 0 || this.is_valid_cell_index(index) || index === ncells) { |
|
867 | if (ncells === 0 || this.is_valid_cell_index(index) || index === ncells) { | |
844 | var cell_options = { |
|
868 | var cell_options = { |
@@ -12,31 +12,66 casper.notebook_test(function () { | |||||
12 | var c = 'print("c")'; |
|
12 | var c = 'print("c")'; | |
13 | index = this.append_cell(c); |
|
13 | index = this.append_cell(c); | |
14 | this.execute_cell_then(index); |
|
14 | this.execute_cell_then(index); | |
15 |
|
15 | |||
|
16 | this.thenEvaluate(function() { | |||
|
17 | IPython.notebook.default_cell_type = 'code'; | |||
|
18 | }); | |||
|
19 | ||||
16 | this.then(function () { |
|
20 | this.then(function () { | |
17 | // Cell insertion |
|
21 | // Cell insertion | |
18 | this.select_cell(2); |
|
22 | this.select_cell(2); | |
|
23 | this.trigger_keydown('m'); // Make it markdown | |||
19 | this.trigger_keydown('a'); // Creates one cell |
|
24 | this.trigger_keydown('a'); // Creates one cell | |
20 | this.test.assertEquals(this.get_cell_text(2), '', 'a; New cell 2 text is empty'); |
|
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 | this.validate_notebook_state('a', 'command', 2); |
|
27 | this.validate_notebook_state('a', 'command', 2); | |
23 | this.trigger_keydown('b'); // Creates one cell |
|
28 | this.trigger_keydown('b'); // Creates one cell | |
24 | this.test.assertEquals(this.get_cell_text(2), '', 'b; Cell 2 text is still empty'); |
|
29 | this.test.assertEquals(this.get_cell_text(2), '', 'b; Cell 2 text is still empty'); | |
25 | this.test.assertEquals(this.get_cell_text(3), '', 'b; New cell 3 text is empty'); |
|
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 | this.validate_notebook_state('b', 'command', 3); |
|
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 | this.then(function () { |
|
39 | this.then(function () { | |
30 | // Cell insertion |
|
|||
31 | this.select_cell(2); |
|
40 | this.select_cell(2); | |
32 | this.trigger_keydown('m'); // switch it to markdown for the next test |
|
41 | this.trigger_keydown('m'); // switch it to markdown for the next test | |
33 | this.trigger_keydown('a'); // Creates one cell |
|
42 | this.test.assertEquals(this.get_cell(2).cell_type, 'markdown', 'test cell is markdown'); | |
34 | this.test.assertEquals(this.get_cell_text(2), '', 'a; New cell 2 text is empty'); |
|
43 | this.trigger_keydown('a'); // new cell above | |
35 |
this.test.assertEquals(this.get_cell(2).cell_type, 'markdown', 'a; inserts a markdown cell when |
|
44 | this.test.assertEquals(this.get_cell(2).cell_type, 'markdown', 'a; inserts a markdown cell when markdown selected'); | |
36 | this.validate_notebook_state('a', 'command', 2); |
|
45 | this.trigger_keydown('b'); // new cell below | |
37 | this.trigger_keydown('b'); // Creates one cell |
|
46 | this.test.assertEquals(this.get_cell(3).cell_type, 'markdown', 'b; inserts a markdown cell when markdown selected'); | |
38 | this.test.assertEquals(this.get_cell_text(2), '', 'b; Cell 2 text is still empty'); |
|
47 | }); | |
39 | this.test.assertEquals(this.get_cell(3).cell_type, 'markdown', 'b; inserts a markdown cell when on markdown cell'); |
|
48 | ||
40 | this.validate_notebook_state('b', 'command', 3); |
|
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