Show More
@@ -406,6 +406,15 b' div.text_cell_render {' | |||||
406 | min-height:50px; |
|
406 | min-height:50px; | |
407 | } |
|
407 | } | |
408 |
|
408 | |||
|
409 | .completions p{ | |||
|
410 | background: #DDF; | |||
|
411 | /*outline: none; | |||
|
412 | padding: 0px;*/ | |||
|
413 | border-bottom: black solid 1px; | |||
|
414 | padding: 1px; | |||
|
415 | font-family: monospace; | |||
|
416 | } | |||
|
417 | ||||
409 | @media print { |
|
418 | @media print { | |
410 | body { overflow: visible !important; } |
|
419 | body { overflow: visible !important; } | |
411 | .ui-widget-content { border: 0px; } |
|
420 | .ui-widget-content { border: 0px; } |
@@ -229,9 +229,10 b' var IPython = (function (IPython) {' | |||||
229 | // setTimeout(CodeCell.prototype.remove_and_cancell_tooltip, 5000); |
|
229 | // setTimeout(CodeCell.prototype.remove_and_cancell_tooltip, 5000); | |
230 | }; |
|
230 | }; | |
231 |
|
231 | |||
232 |
|
232 | // As you type completer | ||
233 | CodeCell.prototype.finish_completing = function (matched_text, matches) { |
|
233 | CodeCell.prototype.finish_completing = function (matched_text, matches) { | |
234 | // console.log("Got matches", matched_text, matches); |
|
234 | ||
|
235 | // smart completion, sort kwarg ending with '=' | |||
235 | var newm = new Array(); |
|
236 | var newm = new Array(); | |
236 | if(this.notebook.smart_completer) |
|
237 | if(this.notebook.smart_completer) | |
237 | { |
|
238 | { | |
@@ -245,6 +246,8 b' var IPython = (function (IPython) {' | |||||
245 | newm = kwargs.concat(other); |
|
246 | newm = kwargs.concat(other); | |
246 | matches=newm; |
|
247 | matches=newm; | |
247 | } |
|
248 | } | |
|
249 | // end sort kwargs | |||
|
250 | ||||
248 | if (!this.is_completing || matches.length === 0) {return;} |
|
251 | if (!this.is_completing || matches.length === 0) {return;} | |
249 |
|
252 | |||
250 | //try to check if the user is typing tab at least twice after a word |
|
253 | //try to check if the user is typing tab at least twice after a word | |
@@ -268,54 +271,90 b' var IPython = (function (IPython) {' | |||||
268 | this.prevmatch=""; |
|
271 | this.prevmatch=""; | |
269 | this.npressed=0; |
|
272 | this.npressed=0; | |
270 | } |
|
273 | } | |
|
274 | // end fallback on tooltip | |||
271 |
|
275 | |||
|
276 | // Real completion logic start here | |||
272 | var that = this; |
|
277 | var that = this; | |
273 | var cur = this.completion_cursor; |
|
278 | var cur = this.completion_cursor; | |
|
279 | var done = false; | |||
|
280 | ||||
|
281 | // call to dismmiss the completer | |||
|
282 | var close = function () { | |||
|
283 | if (done) return; | |||
|
284 | done = true; | |||
|
285 | if (complete!=undefined) | |||
|
286 | {complete.remove();} | |||
|
287 | that.is_completing = false; | |||
|
288 | that.completion_cursor = null; | |||
|
289 | }; | |||
274 |
|
290 | |||
|
291 | // insert the given text and exit the completer | |||
275 | var insert = function (selected_text) { |
|
292 | var insert = function (selected_text) { | |
276 | that.code_mirror.replaceRange( |
|
293 | that.code_mirror.replaceRange( | |
277 | selected_text, |
|
294 | selected_text, | |
278 | {line: cur.line, ch: (cur.ch-matched_text.length)}, |
|
295 | {line: cur.line, ch: (cur.ch-matched_text.length)}, | |
279 | {line: cur.line, ch: cur.ch} |
|
296 | {line: cur.line, ch: cur.ch} | |
280 | ); |
|
297 | ); | |
|
298 | event.stopPropagation(); | |||
|
299 | event.preventDefault(); | |||
|
300 | close(); | |||
|
301 | setTimeout(function(){that.code_mirror.focus();}, 50); | |||
|
302 | }; | |||
|
303 | ||||
|
304 | // insert the curent highlited selection and exit | |||
|
305 | var pick = function () { | |||
|
306 | insert(select.val()[0]); | |||
281 | }; |
|
307 | }; | |
282 |
|
308 | |||
|
309 | // if only one match, complete to it, don't ask user | |||
283 | if (matches.length === 1) { |
|
310 | if (matches.length === 1) { | |
284 | insert(matches[0]); |
|
311 | insert(matches[0]); | |
285 | setTimeout(function(){that.code_mirror.focus();}, 50); |
|
|||
286 | return; |
|
312 | return; | |
287 | }; |
|
313 | }; | |
288 |
|
314 | |||
|
315 | ||||
|
316 | // Define function to clear the completer, refill it with the new | |||
|
317 | // matches, update the pseuso typing field. Note that this is case | |||
|
318 | // insensitive for now | |||
|
319 | var complete_with = function(matches,typed_text) | |||
|
320 | { | |||
|
321 | //clear the previous completion if any | |||
|
322 | if (matches.length < 1) { | |||
|
323 | insert(typed_text); | |||
|
324 | } | |||
|
325 | complete.children().children().remove(); | |||
|
326 | $('#asyoutype').text(typed_text); | |||
|
327 | select=$('#asyoutypeselect'); | |||
|
328 | for (var i=0; i<matches.length; ++i) { | |||
|
329 | select.append($('<option/>').html(matches[i])); | |||
|
330 | } | |||
|
331 | select.children().first().attr('selected','true'); | |||
|
332 | } | |||
|
333 | ||||
|
334 | // create html for completer | |||
289 | var complete = $('<div/>').addClass('completions'); |
|
335 | var complete = $('<div/>').addClass('completions'); | |
|
336 | complete.attr('id','complete'); | |||
|
337 | complete.append($('<p/>').attr('id', 'asyoutype').html(matched_text));//pseudo input field | |||
|
338 | ||||
290 | var select = $('<select/>').attr('multiple','true'); |
|
339 | var select = $('<select/>').attr('multiple','true'); | |
291 | for (var i=0; i<matches.length; ++i) { |
|
340 | select.attr('id', 'asyoutypeselect') | |
292 |
select.a |
|
341 | select.attr('size',Math.min(10,matches.length)); | |
293 | } |
|
|||
294 | select.children().first().attr('selected','true'); |
|
|||
295 | select.attr('size',Math.min(10,matches.length)); |
|
|||
296 | var pos = this.code_mirror.cursorCoords(); |
|
342 | var pos = this.code_mirror.cursorCoords(); | |
|
343 | ||||
|
344 | // TODO: I propose to remove enough horizontal pixel | |||
|
345 | // to align the text later | |||
297 | complete.css('left',pos.x+'px'); |
|
346 | complete.css('left',pos.x+'px'); | |
298 | complete.css('top',pos.yBot+'px'); |
|
347 | complete.css('top',pos.yBot+'px'); | |
299 | complete.append(select); |
|
348 | complete.append(select); | |
300 |
|
349 | |||
301 | $('body').append(complete); |
|
350 | $('body').append(complete); | |
302 | var done = false; |
|
|||
303 |
|
||||
304 | var close = function () { |
|
|||
305 | if (done) return; |
|
|||
306 | done = true; |
|
|||
307 | complete.remove(); |
|
|||
308 | that.is_completing = false; |
|
|||
309 | that.completion_cursor = null; |
|
|||
310 | }; |
|
|||
311 |
|
351 | |||
312 | var pick = function () { |
|
352 | //do a first actual completion | |
313 | insert(select.val()[0]); |
|
353 | complete_with(matches,matched_text); | |
314 | close(); |
|
|||
315 | setTimeout(function(){that.code_mirror.focus();}, 50); |
|
|||
316 | }; |
|
|||
317 |
|
354 | |||
318 | select.blur(close); |
|
355 | // Give focus to select, and make it filter the match as the user type | |
|
356 | // by filtering the previous matches | |||
|
357 | typed_characters = ""; | |||
319 | select.keydown(function (event) { |
|
358 | select.keydown(function (event) { | |
320 | var code = event.which; |
|
359 | var code = event.which; | |
321 | if (code === 13 || code === 32) { |
|
360 | if (code === 13 || code === 32) { | |
@@ -327,16 +366,35 b' var IPython = (function (IPython) {' | |||||
327 | // We don't want the document keydown handler to handle UP/DOWN, |
|
366 | // We don't want the document keydown handler to handle UP/DOWN, | |
328 | // but we want the default action. |
|
367 | // but we want the default action. | |
329 | event.stopPropagation(); |
|
368 | event.stopPropagation(); | |
|
369 | } else if (code>64 && code <90 || code==8){ | |||
|
370 | // issues with _-.. on chrome at least | |||
|
371 | if(code != 8) | |||
|
372 | { | |||
|
373 | var newchar = String.fromCharCode(code).toLowerCase(); | |||
|
374 | typed_characters=typed_characters+newchar; | |||
|
375 | } else { | |||
|
376 | // 8 is backspace remove 1 char cancel if | |||
|
377 | // user have erase everything, otherwise | |||
|
378 | // decrease what we filter with | |||
|
379 | if (typed_characters.length <= 0) | |||
|
380 | { | |||
|
381 | insert(matched_text) | |||
|
382 | } | |||
|
383 | typed_characters=typed_characters.substr(0,typed_characters.length-1); | |||
|
384 | } | |||
|
385 | re = new RegExp("^"+"\%?"+matched_text+typed_characters,"i"); | |||
|
386 | filterd= matches.filter(function(x){return re.test(x)}); | |||
|
387 | complete_with(filterd,matched_text+typed_characters); | |||
330 | } else { |
|
388 | } else { | |
331 |
// |
|
389 | // abort with what the user have pressed until now | |
332 | event.stopPropagation(); |
|
390 | console.log('aborting with keycode : '+code); | |
333 | event.preventDefault(); |
|
391 | insert(matched_text+typed_characters); | |
334 | close(); |
|
|||
335 | that.code_mirror.focus(); |
|
|||
336 | } |
|
392 | } | |
337 | }); |
|
393 | }); | |
338 | // Double click also causes a pick. |
|
394 | // Double click also causes a pick. | |
|
395 | // and bind the last actions. | |||
339 | select.dblclick(pick); |
|
396 | select.dblclick(pick); | |
|
397 | select.blur(close); | |||
340 | select.focus(); |
|
398 | select.focus(); | |
341 | }; |
|
399 | }; | |
342 |
|
400 |
General Comments 0
You need to be logged in to leave comments.
Login now