Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

As you type completer, fix on Firefox #1069

Merged
merged 1 commit into from
Nov 30, 2011
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions IPython/frontend/html/notebook/static/js/codecell.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,36 +318,46 @@ var IPython = (function (IPython) {
};

// insert the given text and exit the completer
var insert = function (selected_text) {
var insert = function (selected_text, event) {
that.code_mirror.replaceRange(
selected_text,
{line: cur.line, ch: (cur.ch-matched_text.length)},
{line: cur.line, ch: cur.ch}
);
event.stopPropagation();
event.preventDefault();
if(event != null){
event.stopPropagation();
event.preventDefault();
}
close();
setTimeout(function(){that.code_mirror.focus();}, 50);
};

// insert the curent highlited selection and exit
var pick = function () {
insert(select.val()[0]);
insert(select.val()[0],null);
};


// Define function to clear the completer, refill it with the new
// matches, update the pseuso typing field. autopick insert match if
// only one left, in no matches (anymore) dismiss itself by pasting
// what the user have typed until then
var complete_with = function(matches,typed_text,autopick)
var complete_with = function(matches,typed_text,autopick,event)
{
// If autopick an only one match, past.
// Used to 'pick' when pressing tab
if (matches.length < 1) {
insert(typed_text);
insert(typed_text,event);
if(event !=null){
event.stopPropagation();
event.preventDefault();
}
} else if (autopick && matches.length==1) {
insert(matches[0]);
insert(matches[0],event);
if(event !=null){
event.stopPropagation();
event.preventDefault();
}
}
//clear the previous completion if any
complete.children().children().remove();
Expand Down Expand Up @@ -381,7 +391,7 @@ var IPython = (function (IPython) {
// the same letter and complete if necessary
fastForward = sharedStart(matches)
typed_characters= fastForward.substr(matched_text.length);
complete_with(matches,matched_text+typed_characters,true);
complete_with(matches,matched_text+typed_characters,true,null);
filterd=matches;
// Give focus to select, and make it filter the match as the user type
// by filtering the previous matches. Called by .keypress and .keydown
Expand All @@ -407,8 +417,8 @@ var IPython = (function (IPython) {
// but we want the default action.
event.stopPropagation();
//} else if ( key.isCompSymbol(code)|| (code==key.backspace)||(code==key.tab && down)){
} else if ( (code==key.backspace)||(code==key.tab) || press || key.isCompSymbol(code)){
if((code != key.backspace) && (code != key.tab) && press)
} else if ( (code==key.backspace)||(code==key.tab && down) || press || key.isCompSymbol(code)){
if( key.isCompSymbol(code) && press)
{
var newchar = String.fromCharCode(code);
typed_characters=typed_characters+newchar;
Expand All @@ -419,22 +429,22 @@ var IPython = (function (IPython) {
autopick=true;
event.stopPropagation();
event.preventDefault();
} else if (code == key.backspace) {
} else if (code == key.backspace && down) {
// cancel if user have erase everything, otherwise decrease
// what we filter with
if (typed_characters.length <= 0)
{
insert(matched_text)
insert(matched_text,event)
}
typed_characters=typed_characters.substr(0,typed_characters.length-1);
}
}else{return}
re = new RegExp("^"+"\%?"+matched_text+typed_characters,"");
filterd = matches.filter(function(x){return re.test(x)});
complete_with(filterd,matched_text+typed_characters,autopick);
complete_with(filterd,matched_text+typed_characters,autopick,event);
} else if(down){ // abort only on .keydown
// abort with what the user have pressed until now
console.log('aborting with keycode : '+code+' is down :'+down);
insert(matched_text+typed_characters);
insert(matched_text+typed_characters,event);
}
}
select.keydown(function (event) {
Expand Down