Navigation Menu

Skip to content

Commit

Permalink
Added multiple tab completion:
Browse files Browse the repository at this point in the history
My msg will be "alejandromg, microp11 say hi"
so I write
al
msg: alejandro
then ", mic"
msg: alejandromg, microp11, then
"say hi"
so the msg will be "alejandromg,microp11, say hi" :P
  • Loading branch information
microp11 committed Apr 1, 2012
1 parent 33f0047 commit a9e7d0e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions public/js/app.js
Expand Up @@ -23,6 +23,9 @@ $(document).ready(function(){
var candidate = ""; //candidate var candidate = ""; //candidate
var source = []; //array of values to be matched var source = []; //array of values to be matched
var sourcePos = 0; //the search starting position var sourcePos = 0; //the search starting position
//used in multi tab completion
var patternPos = -1;
var prePattern = "";
//- //-


window.counter = 0; window.counter = 0;
Expand Down Expand Up @@ -592,24 +595,30 @@ $(document).ready(function(){
if (prevKeyWasTab == false) { if (prevKeyWasTab == false) {
prevKeyWasTab = true; prevKeyWasTab = true;
pattern = $('#text_input').val(); pattern = $('#text_input').val();
patternPos = pattern.lastIndexOf(" ");
if (patternPos != -1 ) {
prePattern = pattern.substr(0, patternPos+1);
pattern = pattern.substr(patternPos+1);
};
pattern = new RegExp("^"+pattern, "i"); pattern = new RegExp("^"+pattern, "i");
sourcePos = 0; sourcePos = 0;
candidate = incrementalSearch(pattern, source, sourcePos); candidate = incrementalSearch(pattern, source, sourcePos);
if (candidate.length > 0) { if (candidate.length > 0) {
//candidate found //candidate found
$('#text_input').val(candidate); $('#text_input').val(prePattern+candidate);
return; return;
} }
} else { } else {
candidate = incrementalSearch(pattern, source, sourcePos); candidate = incrementalSearch(pattern, source, sourcePos);
if (candidate.length > 0) { if (candidate.length > 0) {
//candidate found //candidate found
$('#text_input').val(candidate); $('#text_input').val(prePattern+candidate);
return; return;
} }
} }
} else { } else {
prevKeyWasTab = false; prevKeyWasTab = false;
prePattern = "";
source = nicks; //we do not want the source to change during tabcompletion source = nicks; //we do not want the source to change during tabcompletion
} }
}); });
Expand Down

0 comments on commit a9e7d0e

Please sign in to comment.