Show More
@@ -514,6 +514,12 b' define([' | |||
|
514 | 514 | } |
|
515 | 515 | }; |
|
516 | 516 | |
|
517 | var mergeopt = function(_class, options, overwrite){ | |
|
518 | options = options || {}; | |
|
519 | overwrite = overwrite || {}; | |
|
520 | return $.extend(true, {}, _class.options_default, options, overwrite); | |
|
521 | }; | |
|
522 | ||
|
517 | 523 | var ajax_error_msg = function (jqXHR) { |
|
518 | 524 | // Return a JSON error message if there is one, |
|
519 | 525 | // otherwise the basic HTTP status text. |
@@ -552,6 +558,7 b' define([' | |||
|
552 | 558 | platform: platform, |
|
553 | 559 | is_or_has : is_or_has, |
|
554 | 560 | is_focused : is_focused, |
|
561 | mergeopt: mergeopt, | |
|
555 | 562 | ajax_error_msg : ajax_error_msg, |
|
556 | 563 | log_ajax_error : log_ajax_error, |
|
557 | 564 | }; |
@@ -42,7 +42,7 b' define([' | |||
|
42 | 42 | options = options || {}; |
|
43 | 43 | this.keyboard_manager = options.keyboard_manager; |
|
44 | 44 | this.events = options.events; |
|
45 |
var config = t |
|
|
45 | var config = utils.mergeopt(Cell, options.config); | |
|
46 | 46 | // superclass default overwrite our default |
|
47 | 47 | |
|
48 | 48 | this.placeholder = config.placeholder || ''; |
@@ -94,12 +94,6 b' define([' | |||
|
94 | 94 | Cell.options_default.cm_config.dragDrop = false; |
|
95 | 95 | } |
|
96 | 96 | |
|
97 | Cell.prototype.mergeopt = function(_class, options, overwrite){ | |
|
98 | options = options || {}; | |
|
99 | overwrite = overwrite || {}; | |
|
100 | return $.extend(true, {}, _class.options_default, options, overwrite); | |
|
101 | }; | |
|
102 | ||
|
103 | 97 | /** |
|
104 | 98 | * Empty. Subclasses must implement create_element. |
|
105 | 99 | * This should contain all the code to create the DOM element in notebook |
@@ -76,7 +76,7 b' define([' | |||
|
76 | 76 | onKeyEvent: $.proxy(this.handle_keyevent,this) |
|
77 | 77 | }; |
|
78 | 78 | |
|
79 |
var config = t |
|
|
79 | var config = utils.mergeopt(CodeCell, this.config, {cm_config: cm_overwrite_options}); | |
|
80 | 80 | Cell.apply(this,[{ |
|
81 | 81 | config: config, |
|
82 | 82 | keyboard_manager: options.keyboard_manager, |
@@ -53,7 +53,7 b' 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 b' 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 b' 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 b' 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 = { |
@@ -3,13 +3,14 b'' | |||
|
3 | 3 | |
|
4 | 4 | define([ |
|
5 | 5 | 'base/js/namespace', |
|
6 | 'base/js/utils', | |
|
6 | 7 | 'jquery', |
|
7 | 8 | 'notebook/js/cell', |
|
8 | 9 | 'base/js/security', |
|
9 | 10 | 'notebook/js/mathjaxutils', |
|
10 | 11 | 'notebook/js/celltoolbar', |
|
11 | 12 | 'components/marked/lib/marked', |
|
12 | ], function(IPython, $, cell, security, mathjaxutils, celltoolbar, marked) { | |
|
13 | ], function(IPython, utils, $, cell, security, mathjaxutils, celltoolbar, marked) { | |
|
13 | 14 | "use strict"; |
|
14 | 15 | var Cell = cell.Cell; |
|
15 | 16 | |
@@ -40,7 +41,7 b' define([' | |||
|
40 | 41 | var cm_overwrite_options = { |
|
41 | 42 | onKeyEvent: $.proxy(this.handle_keyevent,this) |
|
42 | 43 | }; |
|
43 |
var config = t |
|
|
44 | var config = utils.mergeopt(TextCell, this.config, {cm_config:cm_overwrite_options}); | |
|
44 | 45 | Cell.apply(this, [{ |
|
45 | 46 | config: config, |
|
46 | 47 | keyboard_manager: options.keyboard_manager, |
@@ -226,7 +227,7 b' define([' | |||
|
226 | 227 | // keyboard_manager: KeyboardManager instance |
|
227 | 228 | // notebook: Notebook instance |
|
228 | 229 | options = options || {}; |
|
229 |
var config = t |
|
|
230 | var config = utils.mergeopt(MarkdownCell, options.config); | |
|
230 | 231 | TextCell.apply(this, [$.extend({}, options, {config: config})]); |
|
231 | 232 | |
|
232 | 233 | this.cell_type = 'markdown'; |
@@ -279,7 +280,7 b' define([' | |||
|
279 | 280 | // keyboard_manager: KeyboardManager instance |
|
280 | 281 | // notebook: Notebook instance |
|
281 | 282 | options = options || {}; |
|
282 |
var config = t |
|
|
283 | var config = utils.mergeopt(RawCell, options.config); | |
|
283 | 284 | TextCell.apply(this, [$.extend({}, options, {config: config})]); |
|
284 | 285 | |
|
285 | 286 | // RawCell should always hide its rendered div |
@@ -339,7 +340,7 b' define([' | |||
|
339 | 340 | // keyboard_manager: KeyboardManager instance |
|
340 | 341 | // notebook: Notebook instance |
|
341 | 342 | options = options || {}; |
|
342 |
var config = t |
|
|
343 | var config = utils.mergeopt(HeadingCell, options.config); | |
|
343 | 344 | TextCell.apply(this, [$.extend({}, options, {config: config})]); |
|
344 | 345 | |
|
345 | 346 | this.level = 1; |
@@ -12,31 +12,66 b' 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