fuzzyFind.

This commit is contained in:
Christopher Jeffrey 2015-04-22 13:32:23 -07:00
parent 861b5ef431
commit 01b2d0b265
2 changed files with 7 additions and 4 deletions

View File

@ -733,6 +733,8 @@ A scrollable list which can display selectable items.
- __down(amount)__ - select item below selected.
- __pick(callback)__ - show/focus list and pick an item. the callback is
executed with the result.
- __fuzzyFind([string/regex/callback])__ - find an item based on its text
content.
#### Form (from Box)

View File

@ -5355,6 +5355,7 @@ List.prototype.appendItem = function(item) {
}
};
List.prototype.find =
List.prototype.fuzzyFind = function(search, back) {
var start = this.selected + (back ? -1 : 1);
@ -5381,17 +5382,17 @@ List.prototype.fuzzyFind = function(search, back) {
if (!back) {
for (var i = start; i < this.ritems.length; i++){
if (test(this.ritems[i])) return i;
if (test(this.items[i].getText())) return i;
}
for (var i = 0; i < start; i++){
if (test(this.ritems[i])) return i;
if (test(this.items[i].getText())) return i;
}
} else {
for (var i = start; i >= 0; i--){
if (test(this.ritems[i])) return i;
if (test(this.items[i].getText())) return i;
}
for (var i = this.ritems.length - 1; i > start; i--){
if (test(this.ritems[i])) return i;
if (test(this.items[i].getText())) return i;
}
}