|
@@
-1,531
+1,565
b''
|
|
1
|
// Copyright (c) IPython Development Team.
|
|
1
|
// Copyright (c) IPython Development Team.
|
|
2
|
// Distributed under the terms of the Modified BSD License.
|
|
2
|
// Distributed under the terms of the Modified BSD License.
|
|
3
|
/**
|
|
3
|
/**
|
|
4
|
*
|
|
4
|
*
|
|
5
|
*
|
|
5
|
*
|
|
6
|
* @module codecell
|
|
6
|
* @module codecell
|
|
7
|
* @namespace codecell
|
|
7
|
* @namespace codecell
|
|
8
|
* @class CodeCell
|
|
8
|
* @class CodeCell
|
|
9
|
*/
|
|
9
|
*/
|
|
10
|
|
|
10
|
|
|
11
|
|
|
11
|
|
|
12
|
define([
|
|
12
|
define([
|
|
13
|
'base/js/namespace',
|
|
13
|
'base/js/namespace',
|
|
14
|
'jquery',
|
|
14
|
'jquery',
|
|
15
|
'base/js/utils',
|
|
15
|
'base/js/utils',
|
|
16
|
'base/js/keyboard',
|
|
16
|
'base/js/keyboard',
|
|
17
|
'notebook/js/cell',
|
|
17
|
'notebook/js/cell',
|
|
18
|
'notebook/js/outputarea',
|
|
18
|
'notebook/js/outputarea',
|
|
19
|
'notebook/js/completer',
|
|
19
|
'notebook/js/completer',
|
|
20
|
'notebook/js/celltoolbar',
|
|
20
|
'notebook/js/celltoolbar',
|
|
21
|
'codemirror/lib/codemirror',
|
|
21
|
'codemirror/lib/codemirror',
|
|
22
|
'codemirror/mode/python/python',
|
|
22
|
'codemirror/mode/python/python',
|
|
23
|
'notebook/js/codemirror-ipython'
|
|
23
|
'notebook/js/codemirror-ipython'
|
|
24
|
], function(IPython, $, utils, keyboard, cell, outputarea, completer, celltoolbar, CodeMirror, cmpython, cmip) {
|
|
24
|
], function(IPython, $, utils, keyboard, cell, outputarea, completer, celltoolbar, CodeMirror, cmpython, cmip) {
|
|
25
|
"use strict";
|
|
25
|
"use strict";
|
|
|
|
|
26
|
|
|
26
|
var Cell = cell.Cell;
|
|
27
|
var Cell = cell.Cell;
|
|
27
|
|
|
28
|
|
|
28
|
/* local util for codemirror */
|
|
29
|
/* local util for codemirror */
|
|
29
|
var posEq = function(a, b) {return a.line == b.line && a.ch == b.ch;};
|
|
30
|
var posEq = function(a, b) {return a.line == b.line && a.ch == b.ch;};
|
|
30
|
|
|
31
|
|
|
31
|
/**
|
|
32
|
/**
|
|
32
|
*
|
|
33
|
*
|
|
33
|
* function to delete until previous non blanking space character
|
|
34
|
* function to delete until previous non blanking space character
|
|
34
|
* or first multiple of 4 tabstop.
|
|
35
|
* or first multiple of 4 tabstop.
|
|
35
|
* @private
|
|
36
|
* @private
|
|
36
|
*/
|
|
37
|
*/
|
|
37
|
CodeMirror.commands.delSpaceToPrevTabStop = function(cm){
|
|
38
|
CodeMirror.commands.delSpaceToPrevTabStop = function(cm){
|
|
38
|
var from = cm.getCursor(true), to = cm.getCursor(false), sel = !posEq(from, to);
|
|
39
|
var from = cm.getCursor(true), to = cm.getCursor(false), sel = !posEq(from, to);
|
|
39
|
if (!posEq(from, to)) { cm.replaceRange("", from, to); return; }
|
|
40
|
if (!posEq(from, to)) { cm.replaceRange("", from, to); return; }
|
|
40
|
var cur = cm.getCursor(), line = cm.getLine(cur.line);
|
|
41
|
var cur = cm.getCursor(), line = cm.getLine(cur.line);
|
|
41
|
var tabsize = cm.getOption('tabSize');
|
|
42
|
var tabsize = cm.getOption('tabSize');
|
|
42
|
var chToPrevTabStop = cur.ch-(Math.ceil(cur.ch/tabsize)-1)*tabsize;
|
|
43
|
var chToPrevTabStop = cur.ch-(Math.ceil(cur.ch/tabsize)-1)*tabsize;
|
|
43
|
from = {ch:cur.ch-chToPrevTabStop,line:cur.line};
|
|
44
|
from = {ch:cur.ch-chToPrevTabStop,line:cur.line};
|
|
44
|
var select = cm.getRange(from,cur);
|
|
45
|
var select = cm.getRange(from,cur);
|
|
45
|
if( select.match(/^\ +$/) !== null){
|
|
46
|
if( select.match(/^\ +$/) !== null){
|
|
46
|
cm.replaceRange("",from,cur);
|
|
47
|
cm.replaceRange("",from,cur);
|
|
47
|
} else {
|
|
48
|
} else {
|
|
48
|
cm.deleteH(-1,"char");
|
|
49
|
cm.deleteH(-1,"char");
|
|
49
|
}
|
|
50
|
}
|
|
50
|
};
|
|
51
|
};
|
|
51
|
|
|
52
|
|
|
52
|
var keycodes = keyboard.keycodes;
|
|
53
|
var keycodes = keyboard.keycodes;
|
|
53
|
|
|
54
|
|
|
54
|
var CodeCell = function (kernel, options) {
|
|
55
|
var CodeCell = function (kernel, options) {
|
|
55
|
// Constructor
|
|
56
|
// Constructor
|
|
56
|
//
|
|
57
|
//
|
|
57
|
// A Cell conceived to write code.
|
|
58
|
// A Cell conceived to write code.
|
|
58
|
//
|
|
59
|
//
|
|
59
|
// Parameters:
|
|
60
|
// Parameters:
|
|
60
|
// kernel: Kernel instance
|
|
61
|
// kernel: Kernel instance
|
|
61
|
// The kernel doesn't have to be set at creation time, in that case
|
|
62
|
// The kernel doesn't have to be set at creation time, in that case
|
|
62
|
// it will be null and set_kernel has to be called later.
|
|
63
|
// it will be null and set_kernel has to be called later.
|
|
63
|
// options: dictionary
|
|
64
|
// options: dictionary
|
|
64
|
// Dictionary of keyword arguments.
|
|
65
|
// Dictionary of keyword arguments.
|
|
65
|
// events: $(Events) instance
|
|
66
|
// events: $(Events) instance
|
|
66
|
// config: dictionary
|
|
67
|
// config: dictionary
|
|
67
|
// keyboard_manager: KeyboardManager instance
|
|
68
|
// keyboard_manager: KeyboardManager instance
|
|
68
|
// notebook: Notebook instance
|
|
69
|
// notebook: Notebook instance
|
|
69
|
// tooltip: Tooltip instance
|
|
70
|
// tooltip: Tooltip instance
|
|
70
|
this.kernel = kernel || null;
|
|
71
|
this.kernel = kernel || null;
|
|
71
|
this.notebook = options.notebook;
|
|
72
|
this.notebook = options.notebook;
|
|
72
|
this.collapsed = false;
|
|
73
|
this.collapsed = false;
|
|
73
|
this.events = options.events;
|
|
74
|
this.events = options.events;
|
|
74
|
this.tooltip = options.tooltip;
|
|
75
|
this.tooltip = options.tooltip;
|
|
75
|
this.config = options.config;
|
|
76
|
this.config = options.config;
|
|
76
|
|
|
77
|
|
|
77
|
// create all attributed in constructor function
|
|
78
|
// create all attributed in constructor function
|
|
78
|
// even if null for V8 VM optimisation
|
|
79
|
// even if null for V8 VM optimisation
|
|
79
|
this.input_prompt_number = null;
|
|
80
|
this.input_prompt_number = null;
|
|
80
|
this.celltoolbar = null;
|
|
81
|
this.celltoolbar = null;
|
|
81
|
this.output_area = null;
|
|
82
|
this.output_area = null;
|
|
|
|
|
83
|
this.active_output_area = [];
|
|
82
|
this.last_msg_id = null;
|
|
84
|
this.last_msg_id = null;
|
|
83
|
this.completer = null;
|
|
85
|
this.completer = null;
|
|
84
|
|
|
86
|
|
|
85
|
|
|
87
|
|
|
86
|
var config = utils.mergeopt(CodeCell, this.config);
|
|
88
|
var config = utils.mergeopt(CodeCell, this.config);
|
|
87
|
Cell.apply(this,[{
|
|
89
|
Cell.apply(this,[{
|
|
88
|
config: config,
|
|
90
|
config: config,
|
|
89
|
keyboard_manager: options.keyboard_manager,
|
|
91
|
keyboard_manager: options.keyboard_manager,
|
|
90
|
events: this.events}]);
|
|
92
|
events: this.events}]);
|
|
91
|
|
|
93
|
|
|
92
|
// Attributes we want to override in this subclass.
|
|
94
|
// Attributes we want to override in this subclass.
|
|
93
|
this.cell_type = "code";
|
|
95
|
this.cell_type = "code";
|
|
94
|
|
|
96
|
|
|
95
|
var that = this;
|
|
97
|
var that = this;
|
|
96
|
this.element.focusout(
|
|
98
|
this.element.focusout(
|
|
97
|
function() { that.auto_highlight(); }
|
|
99
|
function() { that.auto_highlight(); }
|
|
98
|
);
|
|
100
|
);
|
|
99
|
};
|
|
101
|
};
|
|
100
|
|
|
102
|
|
|
101
|
CodeCell.options_default = {
|
|
103
|
CodeCell.options_default = {
|
|
102
|
cm_config : {
|
|
104
|
cm_config : {
|
|
103
|
extraKeys: {
|
|
105
|
extraKeys: {
|
|
104
|
"Tab" : "indentMore",
|
|
106
|
"Tab" : "indentMore",
|
|
105
|
"Shift-Tab" : "indentLess",
|
|
107
|
"Shift-Tab" : "indentLess",
|
|
106
|
"Backspace" : "delSpaceToPrevTabStop",
|
|
108
|
"Backspace" : "delSpaceToPrevTabStop",
|
|
107
|
"Cmd-/" : "toggleComment",
|
|
109
|
"Cmd-/" : "toggleComment",
|
|
108
|
"Ctrl-/" : "toggleComment"
|
|
110
|
"Ctrl-/" : "toggleComment"
|
|
109
|
},
|
|
111
|
},
|
|
110
|
mode: 'ipython',
|
|
112
|
mode: 'ipython',
|
|
111
|
theme: 'ipython',
|
|
113
|
theme: 'ipython',
|
|
112
|
matchBrackets: true
|
|
114
|
matchBrackets: true
|
|
113
|
}
|
|
115
|
}
|
|
114
|
};
|
|
116
|
};
|
|
115
|
|
|
117
|
|
|
116
|
CodeCell.msg_cells = {};
|
|
118
|
CodeCell.msg_cells = {};
|
|
117
|
|
|
119
|
|
|
118
|
CodeCell.prototype = Object.create(Cell.prototype);
|
|
120
|
CodeCell.prototype = Object.create(Cell.prototype);
|
|
119
|
|
|
121
|
|
|
120
|
/**
|
|
122
|
/**
|
|
|
|
|
123
|
* @method get_output_area
|
|
|
|
|
124
|
*/
|
|
|
|
|
125
|
CodeCell.prototype.get_output_area = function () {
|
|
|
|
|
126
|
if (this.active_output_area && this.active_output_area.length > 0) {
|
|
|
|
|
127
|
return this.active_output_area[this.active_output_area.length-1];
|
|
|
|
|
128
|
} else {
|
|
|
|
|
129
|
return this.output_area;
|
|
|
|
|
130
|
}
|
|
|
|
|
131
|
};
|
|
|
|
|
132
|
|
|
|
|
|
133
|
/**
|
|
|
|
|
134
|
* @method push_output_area
|
|
|
|
|
135
|
*/
|
|
|
|
|
136
|
CodeCell.prototype.push_output_area = function (output_area) {
|
|
|
|
|
137
|
this.active_output_area.push(output_area);
|
|
|
|
|
138
|
};
|
|
|
|
|
139
|
|
|
|
|
|
140
|
/**
|
|
|
|
|
141
|
* @method pop_output_area
|
|
|
|
|
142
|
*/
|
|
|
|
|
143
|
CodeCell.prototype.pop_output_area = function () {
|
|
|
|
|
144
|
this.active_output_area.pop();
|
|
|
|
|
145
|
};
|
|
|
|
|
146
|
|
|
|
|
|
147
|
/**
|
|
121
|
* @method auto_highlight
|
|
148
|
* @method auto_highlight
|
|
122
|
*/
|
|
149
|
*/
|
|
123
|
CodeCell.prototype.auto_highlight = function () {
|
|
150
|
CodeCell.prototype.auto_highlight = function () {
|
|
124
|
this._auto_highlight(this.config.cell_magic_highlight);
|
|
151
|
this._auto_highlight(this.config.cell_magic_highlight);
|
|
125
|
};
|
|
152
|
};
|
|
126
|
|
|
153
|
|
|
127
|
/** @method create_element */
|
|
154
|
/** @method create_element */
|
|
128
|
CodeCell.prototype.create_element = function () {
|
|
155
|
CodeCell.prototype.create_element = function () {
|
|
129
|
Cell.prototype.create_element.apply(this, arguments);
|
|
156
|
Cell.prototype.create_element.apply(this, arguments);
|
|
130
|
|
|
157
|
|
|
131
|
var cell = $('<div></div>').addClass('cell code_cell');
|
|
158
|
var cell = $('<div></div>').addClass('cell code_cell');
|
|
132
|
cell.attr('tabindex','2');
|
|
159
|
cell.attr('tabindex','2');
|
|
133
|
|
|
160
|
|
|
134
|
var input = $('<div></div>').addClass('input');
|
|
161
|
var input = $('<div></div>').addClass('input');
|
|
135
|
var prompt = $('<div/>').addClass('prompt input_prompt');
|
|
162
|
var prompt = $('<div/>').addClass('prompt input_prompt');
|
|
136
|
var inner_cell = $('<div/>').addClass('inner_cell');
|
|
163
|
var inner_cell = $('<div/>').addClass('inner_cell');
|
|
137
|
this.celltoolbar = new celltoolbar.CellToolbar({
|
|
164
|
this.celltoolbar = new celltoolbar.CellToolbar({
|
|
138
|
cell: this,
|
|
165
|
cell: this,
|
|
139
|
notebook: this.notebook});
|
|
166
|
notebook: this.notebook});
|
|
140
|
inner_cell.append(this.celltoolbar.element);
|
|
167
|
inner_cell.append(this.celltoolbar.element);
|
|
141
|
var input_area = $('<div/>').addClass('input_area');
|
|
168
|
var input_area = $('<div/>').addClass('input_area');
|
|
142
|
this.code_mirror = new CodeMirror(input_area.get(0), this.cm_config);
|
|
169
|
this.code_mirror = new CodeMirror(input_area.get(0), this.cm_config);
|
|
143
|
this.code_mirror.on('keydown', $.proxy(this.handle_keyevent,this))
|
|
170
|
this.code_mirror.on('keydown', $.proxy(this.handle_keyevent,this))
|
|
144
|
$(this.code_mirror.getInputField()).attr("spellcheck", "false");
|
|
171
|
$(this.code_mirror.getInputField()).attr("spellcheck", "false");
|
|
145
|
inner_cell.append(input_area);
|
|
172
|
inner_cell.append(input_area);
|
|
146
|
input.append(prompt).append(inner_cell);
|
|
173
|
input.append(prompt).append(inner_cell);
|
|
147
|
|
|
174
|
|
|
148
|
var widget_area = $('<div/>')
|
|
175
|
var widget_area = $('<div/>')
|
|
149
|
.addClass('widget-area')
|
|
176
|
.addClass('widget-area')
|
|
150
|
.hide();
|
|
177
|
.hide();
|
|
151
|
this.widget_area = widget_area;
|
|
178
|
this.widget_area = widget_area;
|
|
152
|
var widget_prompt = $('<div/>')
|
|
179
|
var widget_prompt = $('<div/>')
|
|
153
|
.addClass('prompt')
|
|
180
|
.addClass('prompt')
|
|
154
|
.appendTo(widget_area);
|
|
181
|
.appendTo(widget_area);
|
|
155
|
var widget_subarea = $('<div/>')
|
|
182
|
var widget_subarea = $('<div/>')
|
|
156
|
.addClass('widget-subarea')
|
|
183
|
.addClass('widget-subarea')
|
|
157
|
.appendTo(widget_area);
|
|
184
|
.appendTo(widget_area);
|
|
158
|
this.widget_subarea = widget_subarea;
|
|
185
|
this.widget_subarea = widget_subarea;
|
|
159
|
var widget_clear_buton = $('<button />')
|
|
186
|
var widget_clear_buton = $('<button />')
|
|
160
|
.addClass('close')
|
|
187
|
.addClass('close')
|
|
161
|
.html('×')
|
|
188
|
.html('×')
|
|
162
|
.click(function() {
|
|
189
|
.click(function() {
|
|
163
|
widget_area.slideUp('', function(){ widget_subarea.html(''); });
|
|
190
|
widget_area.slideUp('', function(){ widget_subarea.html(''); });
|
|
164
|
})
|
|
191
|
})
|
|
165
|
.appendTo(widget_prompt);
|
|
192
|
.appendTo(widget_prompt);
|
|
166
|
|
|
193
|
|
|
167
|
var output = $('<div></div>');
|
|
194
|
var output = $('<div></div>');
|
|
168
|
cell.append(input).append(widget_area).append(output);
|
|
195
|
cell.append(input).append(widget_area).append(output);
|
|
169
|
this.element = cell;
|
|
196
|
this.element = cell;
|
|
170
|
this.output_area = new outputarea.OutputArea({
|
|
197
|
this.output_area = new outputarea.OutputArea({
|
|
171
|
selector: output,
|
|
198
|
selector: output,
|
|
172
|
prompt_area: true,
|
|
199
|
prompt_area: true,
|
|
173
|
events: this.events,
|
|
200
|
events: this.events,
|
|
174
|
keyboard_manager: this.keyboard_manager});
|
|
201
|
keyboard_manager: this.keyboard_manager});
|
|
175
|
this.completer = new completer.Completer(this, this.events);
|
|
202
|
this.completer = new completer.Completer(this, this.events);
|
|
176
|
};
|
|
203
|
};
|
|
177
|
|
|
204
|
|
|
178
|
/** @method bind_events */
|
|
205
|
/** @method bind_events */
|
|
179
|
CodeCell.prototype.bind_events = function () {
|
|
206
|
CodeCell.prototype.bind_events = function () {
|
|
180
|
Cell.prototype.bind_events.apply(this);
|
|
207
|
Cell.prototype.bind_events.apply(this);
|
|
181
|
var that = this;
|
|
208
|
var that = this;
|
|
182
|
|
|
209
|
|
|
183
|
this.element.focusout(
|
|
210
|
this.element.focusout(
|
|
184
|
function() { that.auto_highlight(); }
|
|
211
|
function() { that.auto_highlight(); }
|
|
185
|
);
|
|
212
|
);
|
|
186
|
};
|
|
213
|
};
|
|
187
|
|
|
214
|
|
|
188
|
|
|
215
|
|
|
189
|
/**
|
|
216
|
/**
|
|
190
|
* This method gets called in CodeMirror's onKeyDown/onKeyPress
|
|
217
|
* This method gets called in CodeMirror's onKeyDown/onKeyPress
|
|
191
|
* handlers and is used to provide custom key handling. Its return
|
|
218
|
* handlers and is used to provide custom key handling. Its return
|
|
192
|
* value is used to determine if CodeMirror should ignore the event:
|
|
219
|
* value is used to determine if CodeMirror should ignore the event:
|
|
193
|
* true = ignore, false = don't ignore.
|
|
220
|
* true = ignore, false = don't ignore.
|
|
194
|
* @method handle_codemirror_keyevent
|
|
221
|
* @method handle_codemirror_keyevent
|
|
195
|
*/
|
|
222
|
*/
|
|
196
|
CodeCell.prototype.handle_codemirror_keyevent = function (editor, event) {
|
|
223
|
CodeCell.prototype.handle_codemirror_keyevent = function (editor, event) {
|
|
197
|
|
|
224
|
|
|
198
|
var that = this;
|
|
225
|
var that = this;
|
|
199
|
// whatever key is pressed, first, cancel the tooltip request before
|
|
226
|
// whatever key is pressed, first, cancel the tooltip request before
|
|
200
|
// they are sent, and remove tooltip if any, except for tab again
|
|
227
|
// they are sent, and remove tooltip if any, except for tab again
|
|
201
|
var tooltip_closed = null;
|
|
228
|
var tooltip_closed = null;
|
|
202
|
if (event.type === 'keydown' && event.which != keycodes.tab ) {
|
|
229
|
if (event.type === 'keydown' && event.which != keycodes.tab ) {
|
|
203
|
tooltip_closed = this.tooltip.remove_and_cancel_tooltip();
|
|
230
|
tooltip_closed = this.tooltip.remove_and_cancel_tooltip();
|
|
204
|
}
|
|
231
|
}
|
|
205
|
|
|
232
|
|
|
206
|
var cur = editor.getCursor();
|
|
233
|
var cur = editor.getCursor();
|
|
207
|
if (event.keyCode === keycodes.enter){
|
|
234
|
if (event.keyCode === keycodes.enter){
|
|
208
|
this.auto_highlight();
|
|
235
|
this.auto_highlight();
|
|
209
|
}
|
|
236
|
}
|
|
210
|
|
|
237
|
|
|
211
|
if (event.which === keycodes.down && event.type === 'keypress' && this.tooltip.time_before_tooltip >= 0) {
|
|
238
|
if (event.which === keycodes.down && event.type === 'keypress' && this.tooltip.time_before_tooltip >= 0) {
|
|
212
|
// triger on keypress (!) otherwise inconsistent event.which depending on plateform
|
|
239
|
// triger on keypress (!) otherwise inconsistent event.which depending on plateform
|
|
213
|
// browser and keyboard layout !
|
|
240
|
// browser and keyboard layout !
|
|
214
|
// Pressing '(' , request tooltip, don't forget to reappend it
|
|
241
|
// Pressing '(' , request tooltip, don't forget to reappend it
|
|
215
|
// The second argument says to hide the tooltip if the docstring
|
|
242
|
// The second argument says to hide the tooltip if the docstring
|
|
216
|
// is actually empty
|
|
243
|
// is actually empty
|
|
217
|
this.tooltip.pending(that, true);
|
|
244
|
this.tooltip.pending(that, true);
|
|
218
|
} else if ( tooltip_closed && event.which === keycodes.esc && event.type === 'keydown') {
|
|
245
|
} else if ( tooltip_closed && event.which === keycodes.esc && event.type === 'keydown') {
|
|
219
|
// If tooltip is active, cancel it. The call to
|
|
246
|
// If tooltip is active, cancel it. The call to
|
|
220
|
// remove_and_cancel_tooltip above doesn't pass, force=true.
|
|
247
|
// remove_and_cancel_tooltip above doesn't pass, force=true.
|
|
221
|
// Because of this it won't actually close the tooltip
|
|
248
|
// Because of this it won't actually close the tooltip
|
|
222
|
// if it is in sticky mode. Thus, we have to check again if it is open
|
|
249
|
// if it is in sticky mode. Thus, we have to check again if it is open
|
|
223
|
// and close it with force=true.
|
|
250
|
// and close it with force=true.
|
|
224
|
if (!this.tooltip._hidden) {
|
|
251
|
if (!this.tooltip._hidden) {
|
|
225
|
this.tooltip.remove_and_cancel_tooltip(true);
|
|
252
|
this.tooltip.remove_and_cancel_tooltip(true);
|
|
226
|
}
|
|
253
|
}
|
|
227
|
// If we closed the tooltip, don't let CM or the global handlers
|
|
254
|
// If we closed the tooltip, don't let CM or the global handlers
|
|
228
|
// handle this event.
|
|
255
|
// handle this event.
|
|
229
|
event.codemirrorIgnore = true;
|
|
256
|
event.codemirrorIgnore = true;
|
|
230
|
event.preventDefault();
|
|
257
|
event.preventDefault();
|
|
231
|
return true;
|
|
258
|
return true;
|
|
232
|
} else if (event.keyCode === keycodes.tab && event.type === 'keydown' && event.shiftKey) {
|
|
259
|
} else if (event.keyCode === keycodes.tab && event.type === 'keydown' && event.shiftKey) {
|
|
233
|
if (editor.somethingSelected() || editor.getSelections().length !== 1){
|
|
260
|
if (editor.somethingSelected() || editor.getSelections().length !== 1){
|
|
234
|
var anchor = editor.getCursor("anchor");
|
|
261
|
var anchor = editor.getCursor("anchor");
|
|
235
|
var head = editor.getCursor("head");
|
|
262
|
var head = editor.getCursor("head");
|
|
236
|
if( anchor.line != head.line){
|
|
263
|
if( anchor.line != head.line){
|
|
237
|
return false;
|
|
264
|
return false;
|
|
238
|
}
|
|
265
|
}
|
|
239
|
}
|
|
266
|
}
|
|
240
|
this.tooltip.request(that);
|
|
267
|
this.tooltip.request(that);
|
|
241
|
event.codemirrorIgnore = true;
|
|
268
|
event.codemirrorIgnore = true;
|
|
242
|
event.preventDefault();
|
|
269
|
event.preventDefault();
|
|
243
|
return true;
|
|
270
|
return true;
|
|
244
|
} else if (event.keyCode === keycodes.tab && event.type == 'keydown') {
|
|
271
|
} else if (event.keyCode === keycodes.tab && event.type == 'keydown') {
|
|
245
|
// Tab completion.
|
|
272
|
// Tab completion.
|
|
246
|
this.tooltip.remove_and_cancel_tooltip();
|
|
273
|
this.tooltip.remove_and_cancel_tooltip();
|
|
247
|
|
|
274
|
|
|
248
|
// completion does not work on multicursor, it might be possible though in some cases
|
|
275
|
// completion does not work on multicursor, it might be possible though in some cases
|
|
249
|
if (editor.somethingSelected() || editor.getSelections().length > 1) {
|
|
276
|
if (editor.somethingSelected() || editor.getSelections().length > 1) {
|
|
250
|
return false;
|
|
277
|
return false;
|
|
251
|
}
|
|
278
|
}
|
|
252
|
var pre_cursor = editor.getRange({line:cur.line,ch:0},cur);
|
|
279
|
var pre_cursor = editor.getRange({line:cur.line,ch:0},cur);
|
|
253
|
if (pre_cursor.trim() === "") {
|
|
280
|
if (pre_cursor.trim() === "") {
|
|
254
|
// Don't autocomplete if the part of the line before the cursor
|
|
281
|
// Don't autocomplete if the part of the line before the cursor
|
|
255
|
// is empty. In this case, let CodeMirror handle indentation.
|
|
282
|
// is empty. In this case, let CodeMirror handle indentation.
|
|
256
|
return false;
|
|
283
|
return false;
|
|
257
|
} else {
|
|
284
|
} else {
|
|
258
|
event.codemirrorIgnore = true;
|
|
285
|
event.codemirrorIgnore = true;
|
|
259
|
event.preventDefault();
|
|
286
|
event.preventDefault();
|
|
260
|
this.completer.startCompletion();
|
|
287
|
this.completer.startCompletion();
|
|
261
|
return true;
|
|
288
|
return true;
|
|
262
|
}
|
|
289
|
}
|
|
263
|
}
|
|
290
|
}
|
|
264
|
|
|
291
|
|
|
265
|
// keyboard event wasn't one of those unique to code cells, let's see
|
|
292
|
// keyboard event wasn't one of those unique to code cells, let's see
|
|
266
|
// if it's one of the generic ones (i.e. check edit mode shortcuts)
|
|
293
|
// if it's one of the generic ones (i.e. check edit mode shortcuts)
|
|
267
|
return Cell.prototype.handle_codemirror_keyevent.apply(this, [editor, event]);
|
|
294
|
return Cell.prototype.handle_codemirror_keyevent.apply(this, [editor, event]);
|
|
268
|
};
|
|
295
|
};
|
|
269
|
|
|
296
|
|
|
270
|
// Kernel related calls.
|
|
297
|
// Kernel related calls.
|
|
271
|
|
|
298
|
|
|
272
|
CodeCell.prototype.set_kernel = function (kernel) {
|
|
299
|
CodeCell.prototype.set_kernel = function (kernel) {
|
|
273
|
this.kernel = kernel;
|
|
300
|
this.kernel = kernel;
|
|
274
|
};
|
|
301
|
};
|
|
275
|
|
|
302
|
|
|
276
|
/**
|
|
303
|
/**
|
|
277
|
* Execute current code cell to the kernel
|
|
304
|
* Execute current code cell to the kernel
|
|
278
|
* @method execute
|
|
305
|
* @method execute
|
|
279
|
*/
|
|
306
|
*/
|
|
280
|
CodeCell.prototype.execute = function () {
|
|
307
|
CodeCell.prototype.execute = function () {
|
|
281
|
if (!this.kernel || !this.kernel.is_connected()) {
|
|
308
|
if (!this.kernel || !this.kernel.is_connected()) {
|
|
282
|
console.log("Can't execute, kernel is not connected.");
|
|
309
|
console.log("Can't execute, kernel is not connected.");
|
|
283
|
return;
|
|
310
|
return;
|
|
284
|
}
|
|
311
|
}
|
|
285
|
|
|
312
|
|
|
286
|
this.output_area.clear_output();
|
|
313
|
this.get_output_area().clear_output();
|
|
287
|
|
|
314
|
|
|
288
|
// Clear widget area
|
|
315
|
// Clear widget area
|
|
289
|
this.widget_subarea.html('');
|
|
316
|
this.widget_subarea.html('');
|
|
290
|
this.widget_subarea.height('');
|
|
317
|
this.widget_subarea.height('');
|
|
291
|
this.widget_area.height('');
|
|
318
|
this.widget_area.height('');
|
|
292
|
this.widget_area.hide();
|
|
319
|
this.widget_area.hide();
|
|
293
|
|
|
320
|
|
|
294
|
this.set_input_prompt('*');
|
|
321
|
this.set_input_prompt('*');
|
|
295
|
this.element.addClass("running");
|
|
322
|
this.element.addClass("running");
|
|
296
|
if (this.last_msg_id) {
|
|
323
|
if (this.last_msg_id) {
|
|
297
|
this.kernel.clear_callbacks_for_msg(this.last_msg_id);
|
|
324
|
this.kernel.clear_callbacks_for_msg(this.last_msg_id);
|
|
298
|
}
|
|
325
|
}
|
|
299
|
var callbacks = this.get_callbacks();
|
|
326
|
var callbacks = this.get_callbacks();
|
|
300
|
|
|
327
|
|
|
301
|
var old_msg_id = this.last_msg_id;
|
|
328
|
var old_msg_id = this.last_msg_id;
|
|
302
|
this.last_msg_id = this.kernel.execute(this.get_text(), callbacks, {silent: false, store_history: true});
|
|
329
|
this.last_msg_id = this.kernel.execute(this.get_text(), callbacks, {silent: false, store_history: true});
|
|
303
|
if (old_msg_id) {
|
|
330
|
if (old_msg_id) {
|
|
304
|
delete CodeCell.msg_cells[old_msg_id];
|
|
331
|
delete CodeCell.msg_cells[old_msg_id];
|
|
305
|
}
|
|
332
|
}
|
|
306
|
CodeCell.msg_cells[this.last_msg_id] = this;
|
|
333
|
CodeCell.msg_cells[this.last_msg_id] = this;
|
|
307
|
this.render();
|
|
334
|
this.render();
|
|
308
|
};
|
|
335
|
};
|
|
309
|
|
|
336
|
|
|
310
|
/**
|
|
337
|
/**
|
|
311
|
* Construct the default callbacks for
|
|
338
|
* Construct the default callbacks for
|
|
312
|
* @method get_callbacks
|
|
339
|
* @method get_callbacks
|
|
313
|
*/
|
|
340
|
*/
|
|
314
|
CodeCell.prototype.get_callbacks = function () {
|
|
341
|
CodeCell.prototype.get_callbacks = function () {
|
|
|
|
|
342
|
var that = this;
|
|
315
|
return {
|
|
343
|
return {
|
|
316
|
shell : {
|
|
344
|
shell : {
|
|
317
|
reply : $.proxy(this._handle_execute_reply, this),
|
|
345
|
reply : $.proxy(this._handle_execute_reply, this),
|
|
318
|
payload : {
|
|
346
|
payload : {
|
|
319
|
set_next_input : $.proxy(this._handle_set_next_input, this),
|
|
347
|
set_next_input : $.proxy(this._handle_set_next_input, this),
|
|
320
|
page : $.proxy(this._open_with_pager, this)
|
|
348
|
page : $.proxy(this._open_with_pager, this)
|
|
321
|
}
|
|
349
|
}
|
|
322
|
},
|
|
350
|
},
|
|
323
|
iopub : {
|
|
351
|
iopub : {
|
|
324
|
output : $.proxy(this.output_area.handle_output, this.output_area),
|
|
352
|
output : function() {
|
|
325
|
clear_output : $.proxy(this.output_area.handle_clear_output, this.output_area),
|
|
353
|
var output_area = that.get_output_area();
|
|
|
|
|
354
|
output_area.handle_output.apply(output_area, arguments);
|
|
|
|
|
355
|
},
|
|
|
|
|
356
|
clear_output : function() {
|
|
|
|
|
357
|
var output_area = that.get_output_area();
|
|
|
|
|
358
|
output_area.handle_clear_output.apply(output_area, arguments);
|
|
|
|
|
359
|
},
|
|
326
|
},
|
|
360
|
},
|
|
327
|
input : $.proxy(this._handle_input_request, this)
|
|
361
|
input : $.proxy(this._handle_input_request, this)
|
|
328
|
};
|
|
362
|
};
|
|
329
|
};
|
|
363
|
};
|
|
330
|
|
|
364
|
|
|
331
|
CodeCell.prototype._open_with_pager = function (payload) {
|
|
365
|
CodeCell.prototype._open_with_pager = function (payload) {
|
|
332
|
this.events.trigger('open_with_text.Pager', payload);
|
|
366
|
this.events.trigger('open_with_text.Pager', payload);
|
|
333
|
};
|
|
367
|
};
|
|
334
|
|
|
368
|
|
|
335
|
/**
|
|
369
|
/**
|
|
336
|
* @method _handle_execute_reply
|
|
370
|
* @method _handle_execute_reply
|
|
337
|
* @private
|
|
371
|
* @private
|
|
338
|
*/
|
|
372
|
*/
|
|
339
|
CodeCell.prototype._handle_execute_reply = function (msg) {
|
|
373
|
CodeCell.prototype._handle_execute_reply = function (msg) {
|
|
340
|
this.set_input_prompt(msg.content.execution_count);
|
|
374
|
this.set_input_prompt(msg.content.execution_count);
|
|
341
|
this.element.removeClass("running");
|
|
375
|
this.element.removeClass("running");
|
|
342
|
this.events.trigger('set_dirty.Notebook', {value: true});
|
|
376
|
this.events.trigger('set_dirty.Notebook', {value: true});
|
|
343
|
};
|
|
377
|
};
|
|
344
|
|
|
378
|
|
|
345
|
/**
|
|
379
|
/**
|
|
346
|
* @method _handle_set_next_input
|
|
380
|
* @method _handle_set_next_input
|
|
347
|
* @private
|
|
381
|
* @private
|
|
348
|
*/
|
|
382
|
*/
|
|
349
|
CodeCell.prototype._handle_set_next_input = function (payload) {
|
|
383
|
CodeCell.prototype._handle_set_next_input = function (payload) {
|
|
350
|
var data = {'cell': this, 'text': payload.text};
|
|
384
|
var data = {'cell': this, 'text': payload.text};
|
|
351
|
this.events.trigger('set_next_input.Notebook', data);
|
|
385
|
this.events.trigger('set_next_input.Notebook', data);
|
|
352
|
};
|
|
386
|
};
|
|
353
|
|
|
387
|
|
|
354
|
/**
|
|
388
|
/**
|
|
355
|
* @method _handle_input_request
|
|
389
|
* @method _handle_input_request
|
|
356
|
* @private
|
|
390
|
* @private
|
|
357
|
*/
|
|
391
|
*/
|
|
358
|
CodeCell.prototype._handle_input_request = function (msg) {
|
|
392
|
CodeCell.prototype._handle_input_request = function (msg) {
|
|
359
|
this.output_area.append_raw_input(msg);
|
|
393
|
this.get_output_area().append_raw_input(msg);
|
|
360
|
};
|
|
394
|
};
|
|
361
|
|
|
395
|
|
|
362
|
|
|
396
|
|
|
363
|
// Basic cell manipulation.
|
|
397
|
// Basic cell manipulation.
|
|
364
|
|
|
398
|
|
|
365
|
CodeCell.prototype.select = function () {
|
|
399
|
CodeCell.prototype.select = function () {
|
|
366
|
var cont = Cell.prototype.select.apply(this);
|
|
400
|
var cont = Cell.prototype.select.apply(this);
|
|
367
|
if (cont) {
|
|
401
|
if (cont) {
|
|
368
|
this.code_mirror.refresh();
|
|
402
|
this.code_mirror.refresh();
|
|
369
|
this.auto_highlight();
|
|
403
|
this.auto_highlight();
|
|
370
|
}
|
|
404
|
}
|
|
371
|
return cont;
|
|
405
|
return cont;
|
|
372
|
};
|
|
406
|
};
|
|
373
|
|
|
407
|
|
|
374
|
CodeCell.prototype.render = function () {
|
|
408
|
CodeCell.prototype.render = function () {
|
|
375
|
var cont = Cell.prototype.render.apply(this);
|
|
409
|
var cont = Cell.prototype.render.apply(this);
|
|
376
|
// Always execute, even if we are already in the rendered state
|
|
410
|
// Always execute, even if we are already in the rendered state
|
|
377
|
return cont;
|
|
411
|
return cont;
|
|
378
|
};
|
|
412
|
};
|
|
379
|
|
|
413
|
|
|
380
|
CodeCell.prototype.select_all = function () {
|
|
414
|
CodeCell.prototype.select_all = function () {
|
|
381
|
var start = {line: 0, ch: 0};
|
|
415
|
var start = {line: 0, ch: 0};
|
|
382
|
var nlines = this.code_mirror.lineCount();
|
|
416
|
var nlines = this.code_mirror.lineCount();
|
|
383
|
var last_line = this.code_mirror.getLine(nlines-1);
|
|
417
|
var last_line = this.code_mirror.getLine(nlines-1);
|
|
384
|
var end = {line: nlines-1, ch: last_line.length};
|
|
418
|
var end = {line: nlines-1, ch: last_line.length};
|
|
385
|
this.code_mirror.setSelection(start, end);
|
|
419
|
this.code_mirror.setSelection(start, end);
|
|
386
|
};
|
|
420
|
};
|
|
387
|
|
|
421
|
|
|
388
|
|
|
422
|
|
|
389
|
CodeCell.prototype.collapse_output = function () {
|
|
423
|
CodeCell.prototype.collapse_output = function () {
|
|
390
|
this.output_area.collapse();
|
|
424
|
this.output_area.collapse();
|
|
391
|
};
|
|
425
|
};
|
|
392
|
|
|
426
|
|
|
393
|
|
|
427
|
|
|
394
|
CodeCell.prototype.expand_output = function () {
|
|
428
|
CodeCell.prototype.expand_output = function () {
|
|
395
|
this.output_area.expand();
|
|
429
|
this.output_area.expand();
|
|
396
|
this.output_area.unscroll_area();
|
|
430
|
this.output_area.unscroll_area();
|
|
397
|
};
|
|
431
|
};
|
|
398
|
|
|
432
|
|
|
399
|
CodeCell.prototype.scroll_output = function () {
|
|
433
|
CodeCell.prototype.scroll_output = function () {
|
|
400
|
this.output_area.expand();
|
|
434
|
this.output_area.expand();
|
|
401
|
this.output_area.scroll_if_long();
|
|
435
|
this.output_area.scroll_if_long();
|
|
402
|
};
|
|
436
|
};
|
|
403
|
|
|
437
|
|
|
404
|
CodeCell.prototype.toggle_output = function () {
|
|
438
|
CodeCell.prototype.toggle_output = function () {
|
|
405
|
this.output_area.toggle_output();
|
|
439
|
this.output_area.toggle_output();
|
|
406
|
};
|
|
440
|
};
|
|
407
|
|
|
441
|
|
|
408
|
CodeCell.prototype.toggle_output_scroll = function () {
|
|
442
|
CodeCell.prototype.toggle_output_scroll = function () {
|
|
409
|
this.output_area.toggle_scroll();
|
|
443
|
this.output_area.toggle_scroll();
|
|
410
|
};
|
|
444
|
};
|
|
411
|
|
|
445
|
|
|
412
|
|
|
446
|
|
|
413
|
CodeCell.input_prompt_classical = function (prompt_value, lines_number) {
|
|
447
|
CodeCell.input_prompt_classical = function (prompt_value, lines_number) {
|
|
414
|
var ns;
|
|
448
|
var ns;
|
|
415
|
if (prompt_value === undefined || prompt_value === null) {
|
|
449
|
if (prompt_value === undefined || prompt_value === null) {
|
|
416
|
ns = " ";
|
|
450
|
ns = " ";
|
|
417
|
} else {
|
|
451
|
} else {
|
|
418
|
ns = encodeURIComponent(prompt_value);
|
|
452
|
ns = encodeURIComponent(prompt_value);
|
|
419
|
}
|
|
453
|
}
|
|
420
|
return 'In [' + ns + ']:';
|
|
454
|
return 'In [' + ns + ']:';
|
|
421
|
};
|
|
455
|
};
|
|
422
|
|
|
456
|
|
|
423
|
CodeCell.input_prompt_continuation = function (prompt_value, lines_number) {
|
|
457
|
CodeCell.input_prompt_continuation = function (prompt_value, lines_number) {
|
|
424
|
var html = [CodeCell.input_prompt_classical(prompt_value, lines_number)];
|
|
458
|
var html = [CodeCell.input_prompt_classical(prompt_value, lines_number)];
|
|
425
|
for(var i=1; i < lines_number; i++) {
|
|
459
|
for(var i=1; i < lines_number; i++) {
|
|
426
|
html.push(['...:']);
|
|
460
|
html.push(['...:']);
|
|
427
|
}
|
|
461
|
}
|
|
428
|
return html.join('<br/>');
|
|
462
|
return html.join('<br/>');
|
|
429
|
};
|
|
463
|
};
|
|
430
|
|
|
464
|
|
|
431
|
CodeCell.input_prompt_function = CodeCell.input_prompt_classical;
|
|
465
|
CodeCell.input_prompt_function = CodeCell.input_prompt_classical;
|
|
432
|
|
|
466
|
|
|
433
|
|
|
467
|
|
|
434
|
CodeCell.prototype.set_input_prompt = function (number) {
|
|
468
|
CodeCell.prototype.set_input_prompt = function (number) {
|
|
435
|
var nline = 1;
|
|
469
|
var nline = 1;
|
|
436
|
if (this.code_mirror !== undefined) {
|
|
470
|
if (this.code_mirror !== undefined) {
|
|
437
|
nline = this.code_mirror.lineCount();
|
|
471
|
nline = this.code_mirror.lineCount();
|
|
438
|
}
|
|
472
|
}
|
|
439
|
this.input_prompt_number = number;
|
|
473
|
this.input_prompt_number = number;
|
|
440
|
var prompt_html = CodeCell.input_prompt_function(this.input_prompt_number, nline);
|
|
474
|
var prompt_html = CodeCell.input_prompt_function(this.input_prompt_number, nline);
|
|
441
|
// This HTML call is okay because the user contents are escaped.
|
|
475
|
// This HTML call is okay because the user contents are escaped.
|
|
442
|
this.element.find('div.input_prompt').html(prompt_html);
|
|
476
|
this.element.find('div.input_prompt').html(prompt_html);
|
|
443
|
};
|
|
477
|
};
|
|
444
|
|
|
478
|
|
|
445
|
|
|
479
|
|
|
446
|
CodeCell.prototype.clear_input = function () {
|
|
480
|
CodeCell.prototype.clear_input = function () {
|
|
447
|
this.code_mirror.setValue('');
|
|
481
|
this.code_mirror.setValue('');
|
|
448
|
};
|
|
482
|
};
|
|
449
|
|
|
483
|
|
|
450
|
|
|
484
|
|
|
451
|
CodeCell.prototype.get_text = function () {
|
|
485
|
CodeCell.prototype.get_text = function () {
|
|
452
|
return this.code_mirror.getValue();
|
|
486
|
return this.code_mirror.getValue();
|
|
453
|
};
|
|
487
|
};
|
|
454
|
|
|
488
|
|
|
455
|
|
|
489
|
|
|
456
|
CodeCell.prototype.set_text = function (code) {
|
|
490
|
CodeCell.prototype.set_text = function (code) {
|
|
457
|
return this.code_mirror.setValue(code);
|
|
491
|
return this.code_mirror.setValue(code);
|
|
458
|
};
|
|
492
|
};
|
|
459
|
|
|
493
|
|
|
460
|
|
|
494
|
|
|
461
|
CodeCell.prototype.clear_output = function (wait) {
|
|
495
|
CodeCell.prototype.clear_output = function (wait) {
|
|
462
|
this.output_area.clear_output(wait);
|
|
496
|
this.get_output_area().clear_output(wait);
|
|
463
|
this.set_input_prompt();
|
|
497
|
this.set_input_prompt();
|
|
464
|
};
|
|
498
|
};
|
|
465
|
|
|
499
|
|
|
466
|
|
|
500
|
|
|
467
|
// JSON serialization
|
|
501
|
// JSON serialization
|
|
468
|
|
|
502
|
|
|
469
|
CodeCell.prototype.fromJSON = function (data) {
|
|
503
|
CodeCell.prototype.fromJSON = function (data) {
|
|
470
|
Cell.prototype.fromJSON.apply(this, arguments);
|
|
504
|
Cell.prototype.fromJSON.apply(this, arguments);
|
|
471
|
if (data.cell_type === 'code') {
|
|
505
|
if (data.cell_type === 'code') {
|
|
472
|
if (data.source !== undefined) {
|
|
506
|
if (data.source !== undefined) {
|
|
473
|
this.set_text(data.source);
|
|
507
|
this.set_text(data.source);
|
|
474
|
// make this value the starting point, so that we can only undo
|
|
508
|
// make this value the starting point, so that we can only undo
|
|
475
|
// to this state, instead of a blank cell
|
|
509
|
// to this state, instead of a blank cell
|
|
476
|
this.code_mirror.clearHistory();
|
|
510
|
this.code_mirror.clearHistory();
|
|
477
|
this.auto_highlight();
|
|
511
|
this.auto_highlight();
|
|
478
|
}
|
|
512
|
}
|
|
479
|
this.set_input_prompt(data.execution_count);
|
|
513
|
this.set_input_prompt(data.execution_count);
|
|
480
|
this.output_area.trusted = data.metadata.trusted || false;
|
|
514
|
this.output_area.trusted = data.metadata.trusted || false;
|
|
481
|
this.output_area.fromJSON(data.outputs);
|
|
515
|
this.output_area.fromJSON(data.outputs);
|
|
482
|
if (data.metadata.collapsed !== undefined) {
|
|
516
|
if (data.metadata.collapsed !== undefined) {
|
|
483
|
if (data.metadata.collapsed) {
|
|
517
|
if (data.metadata.collapsed) {
|
|
484
|
this.collapse_output();
|
|
518
|
this.collapse_output();
|
|
485
|
} else {
|
|
519
|
} else {
|
|
486
|
this.expand_output();
|
|
520
|
this.expand_output();
|
|
487
|
}
|
|
521
|
}
|
|
488
|
}
|
|
522
|
}
|
|
489
|
}
|
|
523
|
}
|
|
490
|
};
|
|
524
|
};
|
|
491
|
|
|
525
|
|
|
492
|
|
|
526
|
|
|
493
|
CodeCell.prototype.toJSON = function () {
|
|
527
|
CodeCell.prototype.toJSON = function () {
|
|
494
|
var data = Cell.prototype.toJSON.apply(this);
|
|
528
|
var data = Cell.prototype.toJSON.apply(this);
|
|
495
|
data.source = this.get_text();
|
|
529
|
data.source = this.get_text();
|
|
496
|
// is finite protect against undefined and '*' value
|
|
530
|
// is finite protect against undefined and '*' value
|
|
497
|
if (isFinite(this.input_prompt_number)) {
|
|
531
|
if (isFinite(this.input_prompt_number)) {
|
|
498
|
data.execution_count = this.input_prompt_number;
|
|
532
|
data.execution_count = this.input_prompt_number;
|
|
499
|
} else {
|
|
533
|
} else {
|
|
500
|
data.execution_count = null;
|
|
534
|
data.execution_count = null;
|
|
501
|
}
|
|
535
|
}
|
|
502
|
var outputs = this.output_area.toJSON();
|
|
536
|
var outputs = this.output_area.toJSON();
|
|
503
|
data.outputs = outputs;
|
|
537
|
data.outputs = outputs;
|
|
504
|
data.metadata.trusted = this.output_area.trusted;
|
|
538
|
data.metadata.trusted = this.output_area.trusted;
|
|
505
|
data.metadata.collapsed = this.output_area.collapsed;
|
|
539
|
data.metadata.collapsed = this.output_area.collapsed;
|
|
506
|
return data;
|
|
540
|
return data;
|
|
507
|
};
|
|
541
|
};
|
|
508
|
|
|
542
|
|
|
509
|
/**
|
|
543
|
/**
|
|
510
|
* handle cell level logic when a cell is unselected
|
|
544
|
* handle cell level logic when a cell is unselected
|
|
511
|
* @method unselect
|
|
545
|
* @method unselect
|
|
512
|
* @return is the action being taken
|
|
546
|
* @return is the action being taken
|
|
513
|
*/
|
|
547
|
*/
|
|
514
|
CodeCell.prototype.unselect = function () {
|
|
548
|
CodeCell.prototype.unselect = function () {
|
|
515
|
var cont = Cell.prototype.unselect.apply(this);
|
|
549
|
var cont = Cell.prototype.unselect.apply(this);
|
|
516
|
if (cont) {
|
|
550
|
if (cont) {
|
|
517
|
// When a code cell is usnelected, make sure that the corresponding
|
|
551
|
// When a code cell is usnelected, make sure that the corresponding
|
|
518
|
// tooltip and completer to that cell is closed.
|
|
552
|
// tooltip and completer to that cell is closed.
|
|
519
|
this.tooltip.remove_and_cancel_tooltip(true);
|
|
553
|
this.tooltip.remove_and_cancel_tooltip(true);
|
|
520
|
if (this.completer !== null) {
|
|
554
|
if (this.completer !== null) {
|
|
521
|
this.completer.close();
|
|
555
|
this.completer.close();
|
|
522
|
}
|
|
556
|
}
|
|
523
|
}
|
|
557
|
}
|
|
524
|
return cont;
|
|
558
|
return cont;
|
|
525
|
};
|
|
559
|
};
|
|
526
|
|
|
560
|
|
|
527
|
// Backwards compatability.
|
|
561
|
// Backwards compatability.
|
|
528
|
IPython.CodeCell = CodeCell;
|
|
562
|
IPython.CodeCell = CodeCell;
|
|
529
|
|
|
563
|
|
|
530
|
return {'CodeCell': CodeCell};
|
|
564
|
return {'CodeCell': CodeCell};
|
|
531
|
});
|
|
565
|
});
|