Clear out old items before drawing new
This commit is contained in:
parent
1b0891b0c3
commit
a5fafc25ae
|
@ -1,15 +1,14 @@
|
||||||
/* jslint node: true */
|
/* jslint node: true */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var MenuView = require('./menu_view.js').MenuView;
|
// ENiGMA½
|
||||||
var ansi = require('./ansi_term.js');
|
const MenuView = require('./menu_view.js').MenuView;
|
||||||
var strUtil = require('./string_util.js');
|
const ansi = require('./ansi_term.js');
|
||||||
var miscUtil = require('./misc_util.js');
|
const strUtil = require('./string_util.js');
|
||||||
var colorCodes = require('./color_codes.js');
|
const colorCodes = require('./color_codes.js');
|
||||||
|
|
||||||
var util = require('util');
|
// deps
|
||||||
var assert = require('assert');
|
const util = require('util');
|
||||||
var _ = require('lodash');
|
|
||||||
|
|
||||||
exports.VerticalMenuView = VerticalMenuView;
|
exports.VerticalMenuView = VerticalMenuView;
|
||||||
|
|
||||||
|
@ -19,7 +18,7 @@ function VerticalMenuView(options) {
|
||||||
|
|
||||||
MenuView.call(this, options);
|
MenuView.call(this, options);
|
||||||
|
|
||||||
var self = this;
|
const self = this;
|
||||||
|
|
||||||
this.performAutoScale = function() {
|
this.performAutoScale = function() {
|
||||||
if(this.autoScale.height) {
|
if(this.autoScale.height) {
|
||||||
|
@ -28,13 +27,13 @@ function VerticalMenuView(options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(self.autoScale.width) {
|
if(self.autoScale.width) {
|
||||||
var l = 0;
|
let maxLen = 0;
|
||||||
self.items.forEach(function item(i) {
|
self.items.forEach( item => {
|
||||||
if(i.text.length > l) {
|
if(item.text.length > maxLen) {
|
||||||
l = Math.min(i.text.length, self.client.term.termWidth - self.position.col);
|
maxLen = Math.min(item.text.length, self.client.term.termWidth - self.position.col);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
self.dimens.width = l + 1;
|
self.dimens.width = maxLen + 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -66,14 +65,14 @@ function VerticalMenuView(options) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
this.drawItem = function(index) {
|
this.drawItem = function(index) {
|
||||||
var item = self.items[index];
|
const item = self.items[index];
|
||||||
|
|
||||||
if(!item) {
|
if(!item) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var focusItem;
|
let focusItem;
|
||||||
var text;
|
let text;
|
||||||
|
|
||||||
if(self.hasFocusItems()) {
|
if(self.hasFocusItems()) {
|
||||||
focusItem = self.focusItems[index];
|
focusItem = self.focusItems[index];
|
||||||
|
@ -119,8 +118,24 @@ VerticalMenuView.prototype.redraw = function() {
|
||||||
this.positionCacheExpired = false;
|
this.positionCacheExpired = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var row = this.position.row;
|
// erase old items
|
||||||
for(var i = this.viewWindow.top; i <= this.viewWindow.bottom; ++i) {
|
// :TODO: optimize this: only needed if a item is removed or new max width < old.
|
||||||
|
if(this.oldDimens) {
|
||||||
|
const blank = new Array(Math.max(this.oldDimens.width, this.dimens.width)).join(' ');
|
||||||
|
let seq = ansi.goto(this.position.row, this.position.col) + this.getSGR() + blank;
|
||||||
|
let row = this.position.row + 1;
|
||||||
|
const endRow = (row + this.oldDimens.height) - 2;
|
||||||
|
|
||||||
|
while(row < endRow) {
|
||||||
|
seq += ansi.goto(row, this.position.col) + blank;
|
||||||
|
row += 1;
|
||||||
|
}
|
||||||
|
this.client.term.write(seq);
|
||||||
|
delete this.oldDimens;
|
||||||
|
}
|
||||||
|
|
||||||
|
let row = this.position.row;
|
||||||
|
for(let i = this.viewWindow.top; i <= this.viewWindow.bottom; ++i) {
|
||||||
this.items[i].row = row;
|
this.items[i].row = row;
|
||||||
row += this.itemSpacing + 1;
|
row += this.itemSpacing + 1;
|
||||||
this.items[i].focused = this.focusedItemIndex === i;
|
this.items[i].focused = this.focusedItemIndex === i;
|
||||||
|
@ -181,6 +196,11 @@ VerticalMenuView.prototype.getData = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
VerticalMenuView.prototype.setItems = function(items) {
|
VerticalMenuView.prototype.setItems = function(items) {
|
||||||
|
// if we have items already, save off their drawing area so we don't leave fragments at redraw
|
||||||
|
if(this.items && this.items.length) {
|
||||||
|
this.oldDimens = this.dimens;
|
||||||
|
}
|
||||||
|
|
||||||
VerticalMenuView.super_.prototype.setItems.call(this, items);
|
VerticalMenuView.super_.prototype.setItems.call(this, items);
|
||||||
|
|
||||||
this.positionCacheExpired = true;
|
this.positionCacheExpired = true;
|
||||||
|
|
Loading…
Reference in New Issue