From 6f0dd5e9b6419b298a2dae982ce8c65b9f250e60 Mon Sep 17 00:00:00 2001 From: tophf Date: Thu, 30 Nov 2017 00:54:40 +0300 Subject: [PATCH] fixup 362d9444: never scroll manage page on toggling a visible entry --- js/dom.js | 12 ++++++------ manage/manage.js | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/js/dom.js b/js/dom.js index 2dab18f7..7e218853 100644 --- a/js/dom.js +++ b/js/dom.js @@ -89,14 +89,14 @@ function onDOMready() { } -function scrollElementIntoView(element) { +function scrollElementIntoView(element, {invalidMarginRatio = .25} = {}) { // align to the top/bottom of the visible area if wasn't visible - const bounds = element.getBoundingClientRect(); - const boundsContainer = element.parentNode.getBoundingClientRect(); + const {top, height} = element.getBoundingClientRect(); + const {top: parentTop, bottom: parentBottom} = element.parentNode.getBoundingClientRect(); const windowHeight = window.innerHeight; - if (bounds.top < Math.max(boundsContainer.top, windowHeight / 4) || - bounds.top > Math.min(boundsContainer.bottom, windowHeight) - bounds.height - windowHeight / 4) { - window.scrollBy(0, bounds.top - windowHeight / 2 + bounds.height); + if (top < Math.max(parentTop, windowHeight * invalidMarginRatio) || + top > Math.min(parentBottom, windowHeight) - height - windowHeight * invalidMarginRatio) { + window.scrollBy(0, top - windowHeight / 2 + height); } } diff --git a/manage/manage.js b/manage/manage.js index 230e14a4..9d53d3e5 100644 --- a/manage/manage.js +++ b/manage/manage.js @@ -406,7 +406,7 @@ function handleUpdate(style, {reason, method} = {}) { filterAndAppend({entry}); if (!entry.matches('.hidden') && reason !== 'import') { animateElement(entry); - scrollElementIntoView(entry); + scrollElementIntoView(entry, {invalidMarginRatio: 0}); } function handleToggledOrCodeOnly() {