parent
3ba251cc2f
commit
2e5da439b0
|
@ -2471,7 +2471,10 @@ Element.prototype.parseContent = function(noTags) {
|
|||
Element.prototype.textLength = function(text) {
|
||||
// return unicode.strWidth(text);
|
||||
if (!this.parseTags) return text.length;
|
||||
return helpers.cleanTags(text).length;
|
||||
return text
|
||||
.replace(/{(\/?)([\w\-,;!#]*)}/g, '')
|
||||
.replace(/\x1b\[[\d;]*m/g, '')
|
||||
.length;
|
||||
};
|
||||
|
||||
// Convert `{red-fg}foo{/red-fg}` to `\x1b[31mfoo\x1b[39m`.
|
||||
|
@ -5139,7 +5142,7 @@ function List(options) {
|
|||
this.mouse = options.mouse || false;
|
||||
|
||||
if (options.items) {
|
||||
this.ritems = this.ritemsSet(options.items);
|
||||
this.ritems = options.items;
|
||||
options.items.forEach(this.add.bind(this));
|
||||
}
|
||||
|
||||
|
@ -5279,20 +5282,12 @@ List.prototype.__proto__ = Box.prototype;
|
|||
|
||||
List.prototype.type = 'list';
|
||||
|
||||
List.prototype.ritemsSet = function(items) {
|
||||
return this.ritems = items.map(helpers.cleanTags);
|
||||
};
|
||||
|
||||
List.prototype.ritemSet = function(item) {
|
||||
return this.ritems.push(helpers.cleanTags(item));
|
||||
};
|
||||
|
||||
List.prototype.add =
|
||||
List.prototype.addItem =
|
||||
List.prototype.appendItem = function(item) {
|
||||
var self = this;
|
||||
|
||||
this.ritemSet(item);
|
||||
this.ritems.push(item);
|
||||
|
||||
// Note: Could potentially use Button here.
|
||||
var options = {
|
||||
|
@ -5387,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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5455,10 +5450,10 @@ List.prototype.setItems = function(items) {
|
|||
this.remove(original[i]);
|
||||
}
|
||||
|
||||
this.ritemsSet(items);
|
||||
this.ritems = items;
|
||||
|
||||
// Try to find our old item if it still exists.
|
||||
sel = this.ritems.indexOf(sel);
|
||||
sel = items.indexOf(sel);
|
||||
if (~sel) {
|
||||
this.select(sel);
|
||||
} else if (items.length === original.length) {
|
||||
|
@ -7305,7 +7300,7 @@ Listbar.prototype.appendItem = function(item, callback) {
|
|||
cmd.element = el;
|
||||
el._.cmd = cmd;
|
||||
|
||||
this.ritemSet(cmd.text);
|
||||
this.ritems.push(cmd.text);
|
||||
this.items.push(el);
|
||||
this.commands.push(cmd);
|
||||
this.append(el);
|
||||
|
@ -9121,12 +9116,6 @@ helpers.merge = merge;
|
|||
helpers.asort = asort;
|
||||
helpers.findFile = findFile;
|
||||
|
||||
helpers.cleanTags = function(text) {
|
||||
return text
|
||||
.replace(/{(\/?)([\w\-,;!#]*)}/g, '')
|
||||
.replace(/\x1b\[[\d;]*m/g, '');
|
||||
};
|
||||
|
||||
/**
|
||||
* Expose
|
||||
*/
|
||||
|
|
|
@ -114,8 +114,7 @@ list.on('keypress', function(ch, key) {
|
|||
});
|
||||
|
||||
list.on('select', function(item, select) {
|
||||
//list.setLabel(' ' + item.getText() + ' ');
|
||||
list.setLabel(' ' + list.ritems[select] + ' ');
|
||||
list.setLabel(' ' + item.getText() + ' ');
|
||||
screen.render();
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue