From b7274a16d435c4fb1e84b77d5521fe02af3fe53d Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Sun, 17 Jul 2016 22:15:43 -0600 Subject: [PATCH] (Yet another) fix for setFocusItemIndex() draw issues! --- core/vertical_menu_view.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/core/vertical_menu_view.js b/core/vertical_menu_view.js index 0d61100d..1772e387 100644 --- a/core/vertical_menu_view.js +++ b/core/vertical_menu_view.js @@ -170,15 +170,11 @@ VerticalMenuView.prototype.setFocusItemIndex = function(index) { top : this.focusedItemIndex, bottom : Math.min(this.focusedItemIndex + this.maxVisibleItems, this.items.length) - 1 }; - } else { - this.viewWindow = { - top : 0, - bottom : Math.min(this.maxVisibleItems, this.items.length) - 1 - }; + + this.positionCacheExpired = false; // skip standard behavior + this.performAutoScale(); } - this.positionCacheExpired = false; // skip standard behavior - this.performAutoScale(); this.redraw(); }; @@ -218,7 +214,7 @@ VerticalMenuView.prototype.focusNext = function() { this.viewWindow = { top : 0, - bottom : Math.min(this.focusedItemIndex + this.maxVisibleItems, this.items.length) - 1 + bottom : Math.min(this.maxVisibleItems, this.items.length) - 1 }; } else { this.focusedItemIndex++; @@ -250,6 +246,12 @@ VerticalMenuView.prototype.focusPrevious = function() { if(this.focusedItemIndex < this.viewWindow.top) { this.viewWindow.top--; this.viewWindow.bottom--; + + // adjust for focus index being set & window needing expansion as we scroll up + const rem = (this.viewWindow.bottom - this.viewWindow.top) + 1; + if(rem < this.maxVisibleItems && (this.items.length - 1) > this.focusedItemIndex) { + this.viewWindow.bottom = this.items.length - 1; + } } }