##// END OF EJS Templates
use strict and clean a little....
Matthias BUSSONNIER -
Show More
@@ -10,6 +10,8 b''
10 10 //============================================================================
11 11
12 12 var IPython = (function (IPython) {
13 "use strict";
14
13 15 var utils = IPython.utils;
14 16
15 17 var CodeCell = function (notebook) {
@@ -22,8 +24,6 b' var IPython = (function (IPython) {'
22 24 this.tooltip_timeout = null;
23 25 this.clear_out_timeout = null;
24 26 IPython.Cell.apply(this, arguments);
25 var that = this;
26 this.ccc = new IPython.Completer(function(ed, callback){that.requestCompletion(ed, callback)});
27 27 };
28 28
29 29
@@ -41,16 +41,18 b' var IPython = (function (IPython) {'
41 41 mode: 'python',
42 42 theme: 'ipython',
43 43 readOnly: this.read_only,
44 onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this),
44 onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this)
45 45 });
46 var that = this;
47 ccm = this.code_mirror;
48 ccc = this.ccc;
49 46 input.append(input_area);
50 47 var output = $('<div></div>').addClass('output vbox');
51 48 cell.append(input).append(output);
52 49 this.element = cell;
53 50 this.collapse();
51
52 // construct a completer
53 // And give it the function to call to get the completion list
54 var that = this;
55 this.completer = new IPython.Completer(this.code_mirror,function(callback){that.requestCompletion(callback)});
54 56 };
55 57
56 58 //TODO, try to diminish the number of parameters.
@@ -79,8 +81,8 b' var IPython = (function (IPython) {'
79 81 // note that we are comparing and setting the time to wait at each key press.
80 82 // a better wqy might be to generate a new function on each time change and
81 83 // assign it to CodeCell.prototype.request_tooltip_after_time
82 tooltip_wait_time = this.notebook.time_before_tooltip;
83 tooltip_on_tab = this.notebook.tooltip_on_tab;
84 var tooltip_wait_time = this.notebook.time_before_tooltip;
85 var tooltip_on_tab = this.notebook.tooltip_on_tab;
84 86 var that = this;
85 87 // whatever key is pressed, first, cancel the tooltip request before
86 88 // they are sent, and remove tooltip if any
@@ -134,8 +136,7 b' var IPython = (function (IPython) {'
134 136 return true;
135 137 } else {
136 138 event.stop();
137 this.ccc.startCompletionFor(this.code_mirror);
138
139 this.completer.startCompletion();
139 140 return true;
140 141 };
141 142 } else if (event.keyCode === 8 && event.type == 'keydown') {
@@ -263,11 +264,10 b' var IPython = (function (IPython) {'
263 264 };
264 265
265 266 // As you type completer
266 CodeCell.prototype.requestCompletion= function(ed,callback)
267 CodeCell.prototype.requestCompletion= function(callback)
267 268 {
268 269 this._compcallback = callback;
269 this._editor = ed;
270 var cur = ed.getCursor();
270 var cur = this.code_mirror.getCursor();
271 271 var pre_cursor = this.code_mirror.getRange({line:cur.line,ch:0},cur);
272 272 pre_cursor.trim();
273 273 // Autocomplete the current line.
@@ -281,11 +281,15 b' var IPython = (function (IPython) {'
281 281 // let's build a function that wrap all that stuff into what is needed for the
282 282 // new completer:
283 283 //
284 var cur = this._editor.getCursor();
285 res = CodeMirror.contextHint(this._editor);
286 for( i=0; i< matches.length ; i++)
284 var cur = this.code_mirror.getCursor();
285 var res = CodeMirror.contextHint(this.code_mirror);
286
287 // append the introspection result, in order, at
288 // at the beginning of the table and compute the replacement rance
289 // from current cursor positon and matched_text length.
290 for(var i= matches.length-1; i>=0 ;--i)
287 291 {
288 res.push(
292 res.unshift(
289 293 {
290 294 str : matches[i],
291 295 type : "introspection",
@@ -295,7 +299,6 b' var IPython = (function (IPython) {'
295 299 )
296 300 }
297 301 this._compcallback(res);
298
299 302 };
300 303
301 304
@@ -343,7 +346,7 b' var IPython = (function (IPython) {'
343 346
344 347
345 348 CodeCell.prototype.append_pyout = function (json, dynamic) {
346 n = json.prompt_number || ' ';
349 var n = json.prompt_number || ' ';
347 350 var toinsert = this.create_output_area();
348 351 toinsert.find('div.prompt').addClass('output_prompt').html('Out[' + n + ']:');
349 352 this.append_mime_type(json, toinsert, dynamic);
@@ -35,7 +35,7 b' var IPython = (function(IPython ) {'
35 35 function sharedStart(B){
36 36 if(B.length == 1){return B[0]}
37 37 var A = new Array()
38 for(i=0; i< B.length; i++)
38 for(var i=0; i< B.length; i++)
39 39 {
40 40 A.push(B[i].str);
41 41 }
@@ -47,6 +47,7 b' var IPython = (function(IPython ) {'
47 47 while(s && tem2.indexOf(tem1) == -1){
48 48 tem1 = tem1.substring(0, --s);
49 49 }
50 if (tem1 == "" ){return null;}
50 51 return { str : tem1,
51 52 type : "computed",
52 53 from : B[0].from,
@@ -57,19 +58,18 b' var IPython = (function(IPython ) {'
57 58 }
58 59
59 60 // user to nsert the given completion
60 var Completer = function(getHints) {
61
61 var Completer = function(editor,getHints) {
62 this.editor = editor;
62 63 this.hintfunc = getHints;
63 64 // if last caractere before cursor is not in this, we stop completing
64 65 this.reg = /[A-Za-z.]/;
65 66 }
66 67
67 Completer.prototype.startCompletionFor = function(ed)
68 Completer.prototype.startCompletion = function()
68 69 {
69 70 // call for a 'first' completion, that will set the editor and do some
70 71 // special behaviour like autopicking if only one completion availlable
71 72 //
72 this.editor = ed;
73 73 if (this.editor.somethingSelected()) return;
74 74 this.done = false;
75 75 // use to get focus back on opera
@@ -101,7 +101,7 b' var IPython = (function(IPython ) {'
101 101 // lets assume for now only one source
102 102 //
103 103 var that = this;
104 this.hintfunc(this.editor,function(result){that._resume_completion(result)});
104 this.hintfunc(function(result){that._resume_completion(result)});
105 105 }
106 106 Completer.prototype._resume_completion = function(results)
107 107 {
@@ -135,7 +135,9 b' var IPython = (function(IPython ) {'
135 135 this.complete = $('<div/>').addClass('completions');
136 136 this.complete.attr('id','complete');
137 137
138 this.sel = $('<select/>').attr('multiple','true');
138 this.sel = $('<select/>')
139 .attr('multiple','true')
140 .attr('size',Math.min(10,this.raw_result.length));
139 141 var pos = this.editor.cursorCoords();
140 142
141 143 // TODO: I propose to remove enough horizontal pixel
@@ -205,7 +207,13 b' var IPython = (function(IPython ) {'
205 207 else if (code == key.space || code == key.backspace) {this.close(); this.editor.focus();}
206 208 else if (code == key.tab){
207 209 //all the fastforwarding operation,
208 this.insert(sharedStart(this.raw_result));
210 //Check that shared start is not null which can append with prefixed completion
211 // like %pylab , pylab have no shred start, and ff will result in py<tab><tab>
212 // to erase py
213 var sh = sharedStart(this.raw_result)
214 if(sh){
215 this.insert(sh);
216 }
209 217 this.close();
210 218 CodeMirror.e_stop(event);
211 219 this.editor.focus();
@@ -1,6 +1,7 b''
1 1 // highly adapted for codemiror jshint
2 2
3 3 (function () {
4 "use strict";
4 5 function forEach(arr, f) {
5 6 for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
6 7 }
@@ -57,7 +58,7 b''
57 58
58 59 // append to arry if not already
59 60 // (here we do it )
60 for( c in candidates )
61 for( var c in candidates )
61 62 {
62 63 if(candidates[c].length >= 1){
63 64 maybeAdd(candidates[c]);}
@@ -220,6 +220,7 b' data-notebook-id={{notebook_id}}'
220 220 <script src="{{ static_url("js/cell.js") }}" type="text/javascript" charset="utf-8"></script>
221 221 <script src="{{ static_url("js/codecell.js") }}" type="text/javascript" charset="utf-8"></script>
222 222 <script src="{{ static_url("js/completer.js") }}" type="text/javascript" charset="utf-8"></script>
223 <script src="{{ static_url("js/context-hint.js") }} charset="utf-8"></script>
223 224 <script src="{{ static_url("js/textcell.js") }}" type="text/javascript" charset="utf-8"></script>
224 225 <script src="{{ static_url("js/kernel.js") }}" type="text/javascript" charset="utf-8"></script>
225 226 <script src="{{ static_url("js/savewidget.js") }}" type="text/javascript" charset="utf-8"></script>
@@ -235,4 +236,3 b' data-notebook-id={{notebook_id}}'
235 236 <script src="{{ static_url("codemirror/lib/util/simple-hint.js") }} charset="utf-8"></script>
236 237
237 238 {% end %}
238
General Comments 0
You need to be logged in to leave comments. Login now