Conceptual MenuItem caching - WIP for testing, will impl. in others if it seems good
This commit is contained in:
parent
a121d60c1b
commit
548ff41467
|
@ -29,6 +29,8 @@ function MenuView(options) {
|
||||||
this.items = [];
|
this.items = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.renderCache = {};
|
||||||
|
|
||||||
this.caseInsensitiveHotKeys = miscUtil.valueWithDefault(options.caseInsensitiveHotKeys, true);
|
this.caseInsensitiveHotKeys = miscUtil.valueWithDefault(options.caseInsensitiveHotKeys, true);
|
||||||
|
|
||||||
this.setHotKeys(options.hotKeys);
|
this.setHotKeys(options.hotKeys);
|
||||||
|
@ -65,6 +67,7 @@ util.inherits(MenuView, View);
|
||||||
MenuView.prototype.setItems = function(items) {
|
MenuView.prototype.setItems = function(items) {
|
||||||
if(Array.isArray(items)) {
|
if(Array.isArray(items)) {
|
||||||
this.sorted = false;
|
this.sorted = false;
|
||||||
|
this.renderCache = {};
|
||||||
|
|
||||||
//
|
//
|
||||||
// Items can be an array of strings or an array of objects.
|
// Items can be an array of strings or an array of objects.
|
||||||
|
@ -98,6 +101,16 @@ MenuView.prototype.setItems = function(items) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
MenuView.prototype.getRenderCacheItem = function(index, focusItem = false) {
|
||||||
|
const item = this.renderCache[index];
|
||||||
|
return item && item[focusItem ? 'focus' : 'standard'];
|
||||||
|
};
|
||||||
|
|
||||||
|
MenuView.prototype.setRenderCacheItem = function(index, rendered, focusItem = false) {
|
||||||
|
this.renderCache[index] = this.renderCache[index] || {};
|
||||||
|
this.renderCache[index][focusItem ? 'focus' : 'standard'] = rendered;
|
||||||
|
};
|
||||||
|
|
||||||
MenuView.prototype.setSort = function(sort) {
|
MenuView.prototype.setSort = function(sort) {
|
||||||
if(this.sorted || !Array.isArray(this.items) || 0 === this.items.length) {
|
if(this.sorted || !Array.isArray(this.items) || 0 === this.items.length) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -64,6 +64,11 @@ function VerticalMenuView(options) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cached = this.getRenderCacheItem(index, item.focused);
|
||||||
|
if(cached) {
|
||||||
|
return self.client.term.write(`${ansi.goto(item.row, self.position.col)}${cached}`);
|
||||||
|
}
|
||||||
|
|
||||||
let text;
|
let text;
|
||||||
let sgr;
|
let sgr;
|
||||||
if(item.focused && self.hasFocusItems()) {
|
if(item.focused && self.hasFocusItems()) {
|
||||||
|
@ -78,9 +83,9 @@ function VerticalMenuView(options) {
|
||||||
sgr = (index === self.focusedItemIndex ? self.getFocusSGR() : self.getSGR());
|
sgr = (index === self.focusedItemIndex ? self.getFocusSGR() : self.getSGR());
|
||||||
}
|
}
|
||||||
|
|
||||||
self.client.term.write(
|
text = `${sgr}${strUtil.pad(text, this.dimens.width, this.fillChar, this.justify)}`;
|
||||||
`${ansi.goto(item.row, self.position.col)}${sgr}${strUtil.pad(text, this.dimens.width, this.fillChar, this.justify)}`
|
self.client.term.write(`${ansi.goto(item.row, self.position.col)}${text}`);
|
||||||
);
|
this.setRenderCacheItem(index, text, item.focused);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue