diff --git a/lib/services/menu.service.ts b/lib/services/menu.service.ts index db7180f4..3ce12357 100644 --- a/lib/services/menu.service.ts +++ b/lib/services/menu.service.ts @@ -41,9 +41,14 @@ export class MenuService { let $activeMethodHost = this.getCurrentMethodEl(); if (!$activeMethodHost) return; var elementInViewPos = this.scrollService.getElementPos($activeMethodHost); - if(isScrolledDown && elementInViewPos === INVIEW_POSITION.BELLOW) { - stable = this.changeActive(CHANGE.NEXT); - continue; + if(isScrolledDown) { + //&& elementInViewPos === INVIEW_POSITION.BELLOW + let $nextEl = this.getRelativeCatOrItem(1); + let nextInViewPos = this.scrollService.getElementPos($nextEl, true); + if (elementInViewPos === INVIEW_POSITION.BELLOW && nextInViewPos === INVIEW_POSITION.ABOVE) { + stable = this.changeActive(CHANGE.NEXT); + continue; + } } if(!isScrolledDown && elementInViewPos === INVIEW_POSITION.ABOVE ) { stable = this.changeActive(CHANGE.BACK); @@ -53,6 +58,25 @@ export class MenuService { } } + getRelativeCatOrItem(offset: number = 0) { + let ptr, cat; + cat = this.categories[this.activeCatIdx]; + if (cat.methods.length === 0) { + ptr = null; + cat = this.categories[this.activeCatIdx + Math.sign(offset)] || cat; + } else { + let cat = this.categories[this.activeCatIdx]; + let idx = this.activeMethodIdx + offset; + if ((idx >= cat.methods.length - 1) || idx < 0) { + cat = this.categories[this.activeCatIdx + Math.sign(offset)] || cat; + idx = offset > 0 ? -1 : cat.methods.length - 1; + } + ptr = cat.methods[idx] && cat.methods[idx].pointer; + } + + return this.getMethodElByPtr(ptr, cat.id); + } + getCurrentMethodEl() { return this.getMethodElByPtr(this.activeMethodPtr, this.categories[this.activeCatIdx].id); diff --git a/lib/services/schema-helper.service.ts b/lib/services/schema-helper.service.ts index dfe96f9b..d720f772 100644 --- a/lib/services/schema-helper.service.ts +++ b/lib/services/schema-helper.service.ts @@ -14,6 +14,7 @@ export interface MenuMethod { active: boolean; summary: string; tag: string; + pointer: string; } export interface MenuCategory { diff --git a/lib/services/scroll.service.ts b/lib/services/scroll.service.ts index bf36f8e9..6b20feab 100644 --- a/lib/services/scroll.service.ts +++ b/lib/services/scroll.service.ts @@ -29,13 +29,14 @@ export class ScrollService { } /* returns 1 if element if above the view, 0 if in view and -1 below the view */ - getElementPos($el) { + getElementPos($el, inverted=false) { let scrollYOffset = this.scrollYOffset(); - if (Math.floor($el.getBoundingClientRect().top) > scrollYOffset) { + let mul = inverted ? -1 : 1; + if (mul*Math.floor($el.getBoundingClientRect().top) > mul*scrollYOffset) { return INVIEW_POSITION.ABOVE; } - if ($el.getBoundingClientRect().bottom <= scrollYOffset) { + if (mul*$el.getBoundingClientRect().bottom <= mul*scrollYOffset) { return INVIEW_POSITION.BELLOW; } return INVIEW_POSITION.INVIEW;