mirror of
https://github.com/embarklabs/neo-blessed.git
synced 2025-02-27 18:10:43 +00:00
always have list item selected.
This commit is contained in:
parent
1625046d9c
commit
4b1365bccc
@ -3936,11 +3936,7 @@ function List(options) {
|
|||||||
options.items.forEach(this.add.bind(this));
|
options.items.forEach(this.add.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.children.length) {
|
this.select(0);
|
||||||
// Will throw if this.parent is not set!
|
|
||||||
// Probably not good to have in a constructor.
|
|
||||||
// this.select(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.mouse) {
|
if (options.mouse) {
|
||||||
this.screen._listenMouse(this);
|
this.screen._listenMouse(this);
|
||||||
@ -4109,6 +4105,10 @@ List.prototype.appendItem = function(item) {
|
|||||||
this.items.push(item);
|
this.items.push(item);
|
||||||
this.append(item);
|
this.append(item);
|
||||||
|
|
||||||
|
if (this.items.length === 1) {
|
||||||
|
this.select(0);
|
||||||
|
}
|
||||||
|
|
||||||
if (this.mouse) {
|
if (this.mouse) {
|
||||||
item.on('click', function(data) {
|
item.on('click', function(data) {
|
||||||
if (self.items[self.selected] === item) {
|
if (self.items[self.selected] === item) {
|
||||||
@ -4131,6 +4131,9 @@ List.prototype.removeItem = function(child) {
|
|||||||
child = this.items.splice(i, 1)[0];
|
child = this.items.splice(i, 1)[0];
|
||||||
this.ritems.splice(i, 1);
|
this.ritems.splice(i, 1);
|
||||||
this.remove(child);
|
this.remove(child);
|
||||||
|
if (i === this.selected) {
|
||||||
|
this.select(i - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -4163,7 +4166,12 @@ List.prototype.setItems = function(items) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
List.prototype.select = function(index) {
|
List.prototype.select = function(index) {
|
||||||
if (!this.items.length) return;
|
if (!this.items.length) {
|
||||||
|
this.selected = 0;
|
||||||
|
this.value = '';
|
||||||
|
this.scrollTo(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof index === 'object') {
|
if (typeof index === 'object') {
|
||||||
index = this.items.indexOf(index);
|
index = this.items.indexOf(index);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user