fuzzyFind improvement.
This commit is contained in:
parent
884b9bcb33
commit
a0daecc8bb
|
@ -125,7 +125,6 @@ var prompt = blessed.prompt({
|
|||
vi: true,
|
||||
mouse: true,
|
||||
tags: true,
|
||||
content: 'Label:',
|
||||
border: 'line',
|
||||
hidden: true
|
||||
});
|
||||
|
|
|
@ -5250,10 +5250,11 @@ List.prototype.appendItem = function(item) {
|
|||
};
|
||||
|
||||
List.prototype.fuzzyFind = function(search, back) {
|
||||
var index = this.getItemIndex(this.selected);
|
||||
var start = this.selected + (back ? -1 : 1);
|
||||
|
||||
if (search[0] === '/' && search[search.length - 1] === '/') {
|
||||
if (typeof search === 'number') search += '';
|
||||
|
||||
if (search && search[0] === '/' && search[search.length - 1] === '/') {
|
||||
try {
|
||||
search = new RegExp(search.slice(1, -1));
|
||||
} catch (e) {
|
||||
|
@ -5261,27 +5262,34 @@ List.prototype.fuzzyFind = function(search, back) {
|
|||
}
|
||||
}
|
||||
|
||||
var finder = typeof search === 'string'
|
||||
var test = typeof search === 'string'
|
||||
? function(item) { return !!~item.indexOf(search); }
|
||||
: search.test.bind(search);
|
||||
: (search.test ? search.test.bind(search) : search);
|
||||
|
||||
if (typeof test !== 'function') {
|
||||
if (this.screen.options.debug) {
|
||||
throw new Error('fuzzyFind(): `test` is not a function.');
|
||||
}
|
||||
return this.selected;
|
||||
}
|
||||
|
||||
if (!back) {
|
||||
for (var i = start; i < this.ritems.length; i++){
|
||||
if (finder(this.ritems[i])) return i;
|
||||
if (test(this.ritems[i])) return i;
|
||||
}
|
||||
for (var i = 0; i < start; i++){
|
||||
if (finder(this.ritems[i])) return i;
|
||||
if (test(this.ritems[i])) return i;
|
||||
}
|
||||
} else {
|
||||
for (var i = start; i >= 0; i--){
|
||||
if (finder(this.ritems[i])) return i;
|
||||
if (test(this.ritems[i])) return i;
|
||||
}
|
||||
for (var i = this.ritems.length - 1; i > start; i--){
|
||||
if (finder(this.ritems[i])) return i;
|
||||
if (test(this.ritems[i])) return i;
|
||||
}
|
||||
}
|
||||
|
||||
return index;
|
||||
return this.selected;
|
||||
};
|
||||
|
||||
List.prototype.getItemIndex = function(child) {
|
||||
|
|
Loading…
Reference in New Issue