diff --git a/src/potreeViewer.js b/src/potreeViewer.js index d14378e..c86df2f 100644 --- a/src/potreeViewer.js +++ b/src/potreeViewer.js @@ -82,7 +82,7 @@ export async function createPotreeViewer( // Helper function to update all point clouds for Accepted filtering function updateAllCloudsAccepted(gradientName) { pointclouds.forEach((pc) => { - pc.material.activeAttributeName = 'accepted' + pc.material.activeAttributeName = 'Accepted' pc.material.gradient = Potree.Gradients[gradientName] }) } @@ -205,6 +205,9 @@ function overrideShaderForGradient(pc) { } } +// Prevent overlapping scroll freezes when activating filters quickly +let suppressionActive = false + /** * Freeze all scrollable ancestors of a given root during an action (e.g., jsTree select) * Need this so that when Elevation control or Accepted filter is activated the sidebar doesn't scroll down to the Scene panel @@ -212,6 +215,13 @@ function overrideShaderForGradient(pc) { * @param {*} action */ function suppressSidebarAutoScroll(action, holdMs = 350) { + // --- Re-entrancy guard --- + if (suppressionActive) { + action() + return + } + suppressionActive = true + // anchor on the tree root; fall back to the menu if not found const treeRoot = document.querySelector('#scene_objects') || @@ -228,8 +238,10 @@ function suppressSidebarAutoScroll(action, holdMs = 350) { if (canScroll) scrollers.push(el) el = el.parentElement } + if (!scrollers.length) { action() + suppressionActive = false return } @@ -261,20 +273,19 @@ function suppressSidebarAutoScroll(action, holdMs = 350) { const origFocus = HTMLElement.prototype.focus HTMLElement.prototype.focus = function (opts) { - // force preventScroll behavior even if caller didn't ask try { origFocus.call(this, { ...(opts || {}), preventScroll: true }) } catch { origFocus.call(this) } } + try { action() } finally { const until = performance.now() + holdMs const restoreLoop = () => { - // keep snapping until the selection animations/handlers settle states.forEach(({ el, top, left }) => { el.scrollTop = top el.scrollLeft = left @@ -297,8 +308,11 @@ function suppressSidebarAutoScroll(action, holdMs = 350) { if (h) el.removeEventListener('scroll', h) el.style.overflow = overflow }) + // --- Release the guard --- + suppressionActive = false } } + requestAnimationFrame(restoreLoop) } }