ritems with no tags.

This commit is contained in:
Christopher Jeffrey 2015-04-22 16:53:46 -07:00
parent 01b2d0b265
commit 3ba251cc2f
2 changed files with 26 additions and 14 deletions

View File

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

View File

@ -114,7 +114,8 @@ list.on('keypress', function(ch, key) {
}); });
list.on('select', function(item, select) { list.on('select', function(item, select) {
list.setLabel(' ' + item.getText() + ' '); //list.setLabel(' ' + item.getText() + ' ');
list.setLabel(' ' + list.ritems[select] + ' ');
screen.render(); screen.render();
}); });