Skip to content

Commit

Permalink
fix(#46): 🐛 Fixed doubleclick disable scrolling bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mariewah committed Oct 30, 2025
2 parents 3d90cb3 + 3eb004c commit e902c80
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/potreeViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
})
}
Expand Down Expand Up @@ -205,13 +205,23 @@ 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
*
* @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') ||
Expand All @@ -228,8 +238,10 @@ function suppressSidebarAutoScroll(action, holdMs = 350) {
if (canScroll) scrollers.push(el)
el = el.parentElement
}

if (!scrollers.length) {
action()
suppressionActive = false
return
}

Expand Down Expand Up @@ -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
Expand All @@ -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)
}
}
Expand Down

0 comments on commit e902c80

Please sign in to comment.