VerticalMenuView 'focusItemAtTop' property, and selection by node ID on WFC
* Add new property to change how focus items are handed in VM * Select node by node iD (key press) on WFC
This commit is contained in:
@@ -11,12 +11,14 @@ const pipeToAnsi = require('./color_codes.js').pipeToAnsi;
|
||||
// deps
|
||||
const util = require('util');
|
||||
const _ = require('lodash');
|
||||
const { throws } = require('assert');
|
||||
|
||||
exports.VerticalMenuView = VerticalMenuView;
|
||||
|
||||
function VerticalMenuView(options) {
|
||||
options.cursor = options.cursor || 'hide';
|
||||
options.justify = options.justify || 'left';
|
||||
this.focusItemAtTop = true;
|
||||
|
||||
MenuView.call(this, options);
|
||||
|
||||
@@ -44,9 +46,11 @@ function VerticalMenuView(options) {
|
||||
this.updateViewVisibleItems = function() {
|
||||
self.maxVisibleItems = Math.ceil(self.dimens.height / (self.itemSpacing + 1));
|
||||
|
||||
const topIndex = (this.focusItemAtTop ? throws.focusedItemIndex : 0) || 0;
|
||||
|
||||
self.viewWindow = {
|
||||
top : self.focusedItemIndex,
|
||||
bottom : Math.min(self.focusedItemIndex + self.maxVisibleItems, self.items.length) - 1,
|
||||
top : topIndex,
|
||||
bottom : Math.min(topIndex + self.maxVisibleItems, self.items.length) - 1,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -143,11 +147,15 @@ VerticalMenuView.prototype.setFocus = function(focused) {
|
||||
VerticalMenuView.prototype.setFocusItemIndex = function(index) {
|
||||
VerticalMenuView.super_.prototype.setFocusItemIndex.call(this, index); // sets this.focusedItemIndex
|
||||
|
||||
const remainAfterFocus = this.items.length - index;
|
||||
const remainAfterFocus = this.focusItemAtTop ?
|
||||
this.items.length - index :
|
||||
this.items.length;
|
||||
if(remainAfterFocus >= this.maxVisibleItems) {
|
||||
const topIndex = (this.focusItemAtTop ? throws.focusedItemIndex : 0) || 0;
|
||||
|
||||
this.viewWindow = {
|
||||
top : this.focusedItemIndex,
|
||||
bottom : Math.min(this.focusedItemIndex + this.maxVisibleItems, this.items.length) - 1
|
||||
top : topIndex,
|
||||
bottom : Math.min(topIndex + this.maxVisibleItems, this.items.length) - 1
|
||||
};
|
||||
|
||||
this.positionCacheExpired = false; // skip standard behavior
|
||||
@@ -343,4 +351,12 @@ VerticalMenuView.prototype.setItemSpacing = function(itemSpacing) {
|
||||
VerticalMenuView.super_.prototype.setItemSpacing.call(this, itemSpacing);
|
||||
|
||||
this.positionCacheExpired = true;
|
||||
};
|
||||
|
||||
VerticalMenuView.prototype.setPropertyValue = function(propName, value) {
|
||||
if (propName === 'focusItemAtTop' && _.isBoolean(value)) {
|
||||
this.focusItemAtTop = value;
|
||||
}
|
||||
|
||||
VerticalMenuView.super_.prototype.setPropertyValue.call(this, propName, value);
|
||||
};
|
||||
Reference in New Issue
Block a user