Open source CapCut alternative.
TypeScript
fix(site): arm the drag click swallower on pointerup only
David Le7127fc4d1658
diff --git a/site/src/cut/lib/drag.ts b/site/src/cut/lib/drag.tsindex 33a07d4a..98a4cfcf 100644--- a/site/src/cut/lib/drag.ts+++ b/site/src/cut/lib/drag.ts@@ -87,11 +87,13 @@ export function startDrag(e: React.PointerEvent, opts: DragOpts) {if (!frame) frame = requestAnimationFrame(flush);};// The gesture owns this pointer through release: the browser may still- // synthesize a click on the common ancestor of the press and the release- // (canceling pointerdown leaves click alone in some engines), and that stray- // click lands on whatever sits under the pointer — the stage would take a- // handle drag's release as play/pause. Armed at release, disarmed by the- // click it eats or by the next press.+ // synthesize a click on the common ancestor of the press and the release,+ // and that stray click lands on whatever sits under the pointer — the stage+ // would take a handle drag's release as play/pause. Armed at pointerup only+ // (a canceled gesture synthesizes no click), disarmed by the click it eats,+ // the next press, or the next keypress — keyboard-activated clicks have no+ // preceding pointerdown, so a keypress is the other signal the swallowed+ // click never came.const swallowClick = (ce: MouseEvent) => {ce.stopPropagation();ce.preventDefault();@@ -100,13 +102,17 @@ export function startDrag(e: React.PointerEvent, opts: DragOpts) {const disarm = () => {window.removeEventListener("click", swallowClick, true);window.removeEventListener("pointerdown", disarm, true);+ window.removeEventListener("keydown", disarm, true);};const up = (ev: PointerEvent) => {window.removeEventListener("pointermove", move);window.removeEventListener("pointerup", up);window.removeEventListener("pointercancel", up);- window.addEventListener("click", swallowClick, true);- window.addEventListener("pointerdown", disarm, true);+ if (ev.type === "pointerup") {+ window.addEventListener("click", swallowClick, true);+ window.addEventListener("pointerdown", disarm, true);+ window.addEventListener("keydown", disarm, true);+ }// Land the last position before the gesture ends, so a fast release// finishes where the pointer was rather than one frame behind it.if (frame) cancelAnimationFrame(frame);