diff --git a/lib/widgets/listtable.js b/lib/widgets/listtable.js index 7f7e38e..16e81fd 100644 --- a/lib/widgets/listtable.js +++ b/lib/widgets/listtable.js @@ -25,7 +25,8 @@ function ListTable(options) { } options = options || {}; - options.shrink = true; + + // options.shrink = true; options.normalShrink = true; options.style = options.style || {}; options.style.border = options.style.border || {}; @@ -37,8 +38,19 @@ function ListTable(options) { options.style.selected = options.style.cell.selected; options.style.item = options.style.cell; + var border = options.border; + if (border + && border.top === false + && border.bottom === false + && border.left === false + && border.right === false) { + delete options.border; + } + List.call(this, options); + options.border = border; + this._header = new Box({ parent: this, left: this.screen.autoPadding ? 0 : this.ileft, @@ -84,7 +96,10 @@ ListTable.prototype._calculateMaxes = Table.prototype._calculateMaxes; ListTable.prototype.setRows = ListTable.prototype.setData = function(rows) { var self = this - , align = this.__align; + , align = this.__align + , selected = this.selected + , original = this.items.slice() + , sel = this.ritems[this.selected]; if (this.visible && this.lpos) { this.clearPos(); @@ -148,7 +163,15 @@ ListTable.prototype.setData = function(rows) { this._header.setFront(); - this.select(0); + // Try to find our old item if it still exists. + sel = this.ritems.indexOf(sel); + if (~sel) { + this.select(sel); + } else if (this.items.length === original.length) { + this.select(selected); + } else { + this.select(Math.min(selected, this.items.length - 1)); + } }; ListTable.prototype._select = ListTable.prototype.select; @@ -183,7 +206,12 @@ ListTable.prototype.render = function() { var height = coords.yl - coords.yi - this.ibottom; - if (!this.border || this.options.noCellBorders) return coords; + var border = this.border; + if (!this.border && this.options.border) { + border = this.options.border; + } + + if (!border || this.options.noCellBorders) return coords; // Draw border with correct angles. ry = 0; @@ -200,7 +228,7 @@ ListTable.prototype.render = function() { lines[yi + ry][xi + rx][0] = battr; lines[yi + ry][xi + rx][1] = '\u252c'; // '┬' // XXX If we alter iheight and itop for no borders - nothing should be written here - if (!self.border.top) { + if (!border.top) { lines[yi + ry][xi + rx][1] = '\u2502'; // '│' } lines[yi + ry].dirty = true; @@ -210,7 +238,7 @@ ListTable.prototype.render = function() { lines[yi + ry][xi + rx][0] = battr; lines[yi + ry][xi + rx][1] = '\u2534'; // '┴' // XXX If we alter iheight and ibottom for no borders - nothing should be written here - if (!self.border.bottom) { + if (!border.bottom) { lines[yi + ry][xi + rx][1] = '\u2502'; // '│' } lines[yi + ry].dirty = true;