HOME/END key support in lists

This commit is contained in:
Bryan Ashby 2018-06-09 22:45:01 -06:00
parent 1cb811576b
commit 973e10fb8b
2 changed files with 31 additions and 6 deletions

View File

@ -60,6 +60,10 @@ function MenuView(options) {
}
return -1;
};
this.emitIndexUpdate = function() {
self.emit('index update', self.focusedItemIndex);
}
}
util.inherits(MenuView, View);
@ -174,19 +178,27 @@ MenuView.prototype.getItem = function(index) {
};
MenuView.prototype.focusNext = function() {
this.emit('index update', this.focusedItemIndex);
this.emitIndexUpdate();
};
MenuView.prototype.focusPrevious = function() {
this.emit('index update', this.focusedItemIndex);
this.emitIndexUpdate();
};
MenuView.prototype.focusNextPageItem = function() {
this.emit('index update', this.focusedItemIndex);
this.emitIndexUpdate();
};
MenuView.prototype.focusPreviousPageItem = function() {
this.emit('index update', this.focusedItemIndex);
this.emitIndexUpdate();
};
MenuView.prototype.focusFirst = function() {
this.emitIndexUpdate();
};
MenuView.prototype.focusLast = function() {
this.emitIndexUpdate();
};
MenuView.prototype.setFocusItemIndex = function(index) {

View File

@ -165,7 +165,6 @@ VerticalMenuView.prototype.setFocusItemIndex = function(index) {
};
VerticalMenuView.prototype.onKeyPress = function(ch, key) {
if(key) {
if(this.isKeyMapped('up', key.name)) {
this.focusPrevious();
@ -173,8 +172,12 @@ VerticalMenuView.prototype.onKeyPress = function(ch, key) {
this.focusNext();
} else if(this.isKeyMapped('page up', key.name)) {
this.focusPreviousPageItem();
} else if( this.isKeyMapped('page down', key.name)) {
} else if(this.isKeyMapped('page down', key.name)) {
this.focusNextPageItem();
} else if(this.isKeyMapped('home', key.name)) {
this.focusFirst();
} else if(this.isKeyMapped('end', key.name)) {
this.focusLast();
}
}
@ -308,6 +311,16 @@ VerticalMenuView.prototype.focusNextPageItem = function() {
return VerticalMenuView.super_.prototype.focusNextPageItem.call(this);
};
VerticalMenuView.prototype.focusFirst = function() {
this.setFocusItemIndex(0);
return VerticalMenuView.super_.prototype.focusFirst.call(this);
};
VerticalMenuView.prototype.focusLast = function() {
this.setFocusItemIndex(this.items.length - 1);
return VerticalMenuView.super_.prototype.focusLast.call(this);
};
VerticalMenuView.prototype.setFocusItems = function(items) {
VerticalMenuView.super_.prototype.setFocusItems.call(this, items);