refactor fuzzyFind.

This commit is contained in:
Christopher Jeffrey 2014-06-11 03:03:32 -05:00
parent 5b249d3fec
commit 4cf8be871d
1 changed files with 5 additions and 4 deletions

View File

@ -4172,7 +4172,7 @@ function List(options) {
return;
}
self.options.search(function(searchString){
return self.options.search(function(searchString){
self.select(self.fuzzyFind(searchString));
self.screen.render();
})
@ -4271,16 +4271,17 @@ List.prototype.appendItem = function(item) {
}
};
List.prototype.fuzzyFind = function(searchString) {
List.prototype.fuzzyFind = function(search) {
var index = this.getItemIndex(this.selected);
for (var i = 0; i < this.ritems.length; i++){
if (this.ritems[i].match(new RegExp('^' + searchString))){
if (this.ritems[i].indexOf(search) === 0) {
return i;
}
}
return index;
}
};
List.prototype.getItemIndex = function(child) {
if (typeof child === 'number') {