Skip to content
Browse files

Added multiple tab completion:

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...
1 parent 33f0047 commit a9e7d0e9f6e16c957abba8e0c03700f0ac60d0d4 Paul Maxan committed Apr 1, 2012
Showing with 11 additions and 2 deletions.
  1. +11 −2 public/js/app.js
View
13 public/js/app.js
@@ -23,6 +23,9 @@ $(document).ready(function(){
var candidate = ""; //candidate
var source = []; //array of values to be matched
var sourcePos = 0; //the search starting position
+ //used in multi tab completion
+ var patternPos = -1;
+ var prePattern = "";
//-
window.counter = 0;
@@ -592,24 +595,30 @@ $(document).ready(function(){
if (prevKeyWasTab == false) {
prevKeyWasTab = true;
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");
sourcePos = 0;
candidate = incrementalSearch(pattern, source, sourcePos);
if (candidate.length > 0) {
//candidate found
- $('#text_input').val(candidate);
+ $('#text_input').val(prePattern+candidate);
return;
}
} else {
candidate = incrementalSearch(pattern, source, sourcePos);
if (candidate.length > 0) {
//candidate found
- $('#text_input').val(candidate);
+ $('#text_input').val(prePattern+candidate);
return;
}
}
} else {
prevKeyWasTab = false;
+ prePattern = "";
source = nicks; //we do not want the source to change during tabcompletion
}
});

0 comments on commit a9e7d0e

Please sign in to comment.
Something went wrong with that request. Please try again.