diff --git a/lib/widget.js b/lib/widget.js index b834baf..152c56d 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -4147,7 +4147,7 @@ function List(options) { } self.options.search(function(searchString){ - self.select(self.getItemIndex(searchString)); + self.select(self.fuzzyFind(searchString)); self.screen.render(); }) } @@ -4245,6 +4245,17 @@ List.prototype.appendItem = function(item) { } }; +List.prototype.fuzzyFind = function(searchString) { + var index = this.getItemIndex(this.selected); + + for (var i = 0; i < this.ritems.length; i++){ + if (this.ritems[i].match(new RegExp('^' + searchString))){ + return i; + } + } + return index; +} + List.prototype.getItemIndex = function(child) { if (typeof child === 'number') { return child;