// function completer.
//
// completer should be a class that take an editor instance, and a list of
// function to call to get the list of completion.
//
// the function that send back the list of completion should received the
// editor handle as sole argument, and should return a json object with the
// following structure
// {list: clist, # list of n string containing the completions
// type : rp, # list of n string containingtype/ origin of the completion
// # (will be set as the class of the ')
.text(completions[i].str)
.addClass(completions[i].type);
this.sel.append(opt);
}
this.sel.children().first().attr('selected','true');
//sel.size = Math.min(10, completions.length);
// Hack to hide the scrollbar.
//if (completions.length <= 10)
//this.complete.style.width = (this.sel.clientWidth - 1) + "px";
}
Completer.prototype.close = function() {
if (this.done) return;
this.done = true;
$('.completions').remove();
}
Completer.prototype.pick = function(){
this.insert(this.raw_result[this.sel[0].selectedIndex]);
this.close();
var that = this;
setTimeout(function(){that.editor.focus();}, 50);
}
Completer.prototype.keydown = function(event) {
var code = event.keyCode;
// Enter
if (code == key.enter) {CodeMirror.e_stop(event); this.pick();}
// Escape or backspace
else if (code == key.esc ) {CodeMirror.e_stop(event); this.close(); this.editor.focus();}
else if (code == key.space || code == key.backspace) {this.close(); this.editor.focus();}
else if (code == key.tab){
//all the fastforwarding operation,
//Check that shared start is not null which can append with prefixed completion
// like %pylab , pylab have no shred start, and ff will result in py
// to erase py
var sh = sharedStart(this.raw_result)
if(sh){
this.insert(sh);
}
this.close();
CodeMirror.e_stop(event);
this.editor.focus();
//reinvoke self
var that = this;
setTimeout(function(){that.carryOnCompletion();}, 50);
}
else if (code == key.upArrow || code == key.downArrow) {
// need to do that to be able to move the arrow
// when on the first or last line ofo a code cell
event.stopPropagation();
}
else if (code != key.upArrow && code != key.downArrow) {
this.close(); this.editor.focus();
//we give focus to the editor immediately and call sell in 50 ms
var that = this;
setTimeout(function(){that.carryOnCompletion();}, 50);
}
}
IPython.Completer = Completer;
return IPython;
}(IPython));