diff --git a/lib/widget.js b/lib/widget.js index 2c9266e..3e0ea52 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -4223,7 +4223,7 @@ List.prototype.removeItem = function(child) { List.prototype.setItems = function(items) { var i = 0 , original = this.items.slice() - //, selected = this.selected + , selected = this.selected , sel = this.ritems[this.selected]; this.select(0); @@ -4244,8 +4244,13 @@ List.prototype.setItems = function(items) { // Try to find our old item if it still exists. sel = items.indexOf(sel); - if (~sel) this.select(sel); - //this.select(~sel ? sel : selected); + if (~sel) { + this.select(sel); + } else if (items.length === original.length) { + this.select(selected); + } else { + this.select(Math.min(selected, items.length - 1)); + } }; List.prototype.select = function(index) {