##// END OF EJS Templates
band-aid for completion...
MinRK -
Show More
@@ -28,7 +28,7 var IPython = (function (IPython) {
28 28 if (B.length == 1) {
29 29 return B[0];
30 30 }
31 var A = new Array();
31 var A = [];
32 32 var common;
33 33 var min_lead_prct = 10;
34 34 for (var i = 0; i < B.length; i++) {
@@ -102,7 +102,7 var IPython = (function (IPython) {
102 102
103 103 Completer.prototype.reinvoke= function(pre_cursor, block, cursor){
104 104 return Completer.reinvoke_re.test(pre_cursor);
105 }
105 };
106 106
107 107 /**
108 108 *
@@ -140,15 +140,15 var IPython = (function (IPython) {
140 140 // We want a single cursor position.
141 141 if (this.editor.somethingSelected()) {
142 142 return;
143 };
143 }
144 144
145 145 // one kernel completion came back, finish_completing will be called with the results
146 146 // we fork here and directly call finish completing if kernel is busy
147 if (this.skip_kernel_completion == true) {
147 if (this.skip_kernel_completion) {
148 148 this.finish_completing({
149 149 'matches': [],
150 150 matched_text: ""
151 })
151 });
152 152 } else {
153 153 this.cell.kernel.complete(line, cur.ch, $.proxy(this.finish_completing, this));
154 154 }
@@ -163,19 +163,20 var IPython = (function (IPython) {
163 163
164 164 var cur = this.editor.getCursor();
165 165 var results = CodeMirror.contextHint(this.editor);
166 var filterd_results = Array();
166 var filtered_results = [];
167 167 //remove results from context completion
168 168 //that are already in kernel completion
169 for(var elm in results) {
170 if(_existing_completion(results[elm]['str'], matches) == false)
171 { filterd_results.push(results[elm]); }
169 for (var elm in results) {
170 if (!_existing_completion(results[elm].str, matches)) {
171 filtered_results.push(results[elm]);
172 }
172 173 }
173 174
174 175 // append the introspection result, in order, at at the beginning of
175 176 // the table and compute the replacement range from current cursor
176 177 // positon and matched_text length.
177 178 for (var i = matches.length - 1; i >= 0; --i) {
178 filterd_results.unshift({
179 filtered_results.unshift({
179 180 str: matches[i],
180 181 type: "introspection",
181 182 from: {
@@ -190,13 +191,13 var IPython = (function (IPython) {
190 191 }
191 192
192 193 // one the 2 sources results have been merge, deal with it
193 this.raw_result = filterd_results;
194 this.raw_result = filtered_results;
194 195
195 196 // if empty result return
196 197 if (!this.raw_result || !this.raw_result.length) return;
197 198
198 199 // When there is only one completion, use it directly.
199 if (this.autopick == true && this.raw_result.length == 1) {
200 if (this.autopick && this.raw_result.length == 1) {
200 201 this.insert(this.raw_result[0]);
201 202 return;
202 203 }
@@ -228,7 +229,6 var IPython = (function (IPython) {
228 229
229 230 // After everything is on the page, compute the postion.
230 231 // We put it above the code if it is too close to the bottom of the page.
231 var cur = this.editor.getCursor();
232 232 cur.ch = cur.ch-matched_text.length;
233 233 var pos = this.editor.cursorCoords(cur);
234 234 var left = pos.left-3;
@@ -253,6 +253,9 var IPython = (function (IPython) {
253 253 this.sel.keydown(function (event) {
254 254 that.keydown(event);
255 255 });
256 this.sel.keypress(function (event) {
257 that.keypress(event);
258 });
256 259
257 260 this.build_gui_list(this.raw_result);
258 261
@@ -263,11 +266,11 var IPython = (function (IPython) {
263 266 if (!this.done) this.sel.focus();
264 267 }, 100);
265 268 return true;
266 }
269 };
267 270
268 271 Completer.prototype.insert = function (completion) {
269 272 this.editor.replaceRange(completion.str, completion.from, completion.to);
270 }
273 };
271 274
272 275 Completer.prototype.build_gui_list = function (completions) {
273 276 for (var i = 0; i < completions.length; ++i) {
@@ -276,14 +279,14 var IPython = (function (IPython) {
276 279 }
277 280 this.sel.children().first().attr('selected', 'true');
278 281 this.sel.scrollTop(0);
279 }
282 };
280 283
281 284 Completer.prototype.close = function () {
282 285 if (this.done) return;
283 286 this.done = true;
284 287 $('.completions').remove();
285 288 IPython.keyboard_manager.enable();
286 }
289 };
287 290
288 291 Completer.prototype.pick = function () {
289 292 this.insert(this.raw_result[this.sel[0].selectedIndex]);
@@ -292,8 +295,7 var IPython = (function (IPython) {
292 295 setTimeout(function () {
293 296 that.editor.focus();
294 297 }, 50);
295 }
296
298 };
297 299
298 300 Completer.prototype.keydown = function (event) {
299 301 var code = event.keyCode;
@@ -305,7 +307,7 var IPython = (function (IPython) {
305 307 if (code == key[_key] ) {
306 308 special_key = true;
307 309 }
308 };
310 }
309 311
310 312 // Enter
311 313 if (code == key.ENTER) {
@@ -317,7 +319,7 var IPython = (function (IPython) {
317 319 CodeMirror.e_stop(event);
318 320 this.close();
319 321 this.editor.focus();
320 } else if (code == key.SPACE || code == key.BACKSPACE) {
322 } else if (code == key.BACKSPACE) {
321 323 this.close();
322 324 this.editor.focus();
323 325 } else if (code == key.TAB) {
@@ -340,16 +342,41 var IPython = (function (IPython) {
340 342 // need to do that to be able to move the arrow
341 343 // when on the first or last line ofo a code cell
342 344 event.stopPropagation();
343 } else if (special_key != true) {
344 this.close();
345 this.editor.focus();
346 //we give focus to the editor immediately and call sell in 50 ms
347 setTimeout(function () {
348 that.carry_on_completion();
349 }, 50);
350 345 }
351 }
352
346 };
347
348 Completer.prototype.keypress = function (event) {
349 // FIXME: This is a band-aid.
350 // on keypress, trigger insertion of a single character.
351 // This simulates the old behavior of completion as you type,
352 // before events were disconnected and CodeMirror stopped
353 // receiving events while the completer is focused.
354
355 var that = this;
356 var code = event.keyCode;
357
358 // don't handle keypress if it's not a character (arrows on FF)
359 // or ENTER/TAB
360 if (event.charCode === 0 ||
361 code == key.ENTER ||
362 code == key.TAB
363 ) return;
364
365 var cur = this.editor.getCursor();
366 var completion = {
367 str: String.fromCharCode(event.which),
368 type: "introspection",
369 from: cur,
370 to: cur,
371 };
372 this.insert(completion);
373
374 this.close();
375 this.editor.focus();
376 setTimeout(function () {
377 that.carry_on_completion();
378 }, 50);
379 };
353 380
354 381 IPython.Completer = Completer;
355 382
General Comments 0
You need to be logged in to leave comments. Login now