chore(studio): remove debug logging (#1765)

This commit is contained in:
Miguel Ángel
2026-06-27 11:34:14 -04:00
committed by GitHub
parent bc5a51a6ee
commit de42af438a
7 changed files with 75 additions and 19 deletions
@@ -3,6 +3,7 @@ import { liveTime, usePlayerStore } from "../player";
import { pauseStudioPreviewPlayback } from "../utils/studioPreviewHelpers";
import { STUDIO_PREVIEW_SELECTION_ENABLED } from "../components/editor/manualEditingAvailability";
import { type DomEditSelection } from "../components/editor/domEditing";
import { trackStudioEvent } from "../utils/studioTelemetry";
// ── Types ──
@@ -47,6 +48,12 @@ interface ClickCycleState {
const CYCLE_RADIUS_PX = 6;
const CYCLE_WINDOW_MS = 600;
// Manual double-click window. `e.detail` can't be trusted here: the first click
// selects the group and re-renders the overlay, so the second click lands on a
// fresh element and the browser's native click-counter resets to 1 — drill-in
// (which keyed off `e.detail >= 2`) never fired. We track time+position instead.
const DOUBLE_CLICK_MS = 400;
const DOUBLE_CLICK_RADIUS_PX = 6;
// ── Hook ──
@@ -63,21 +70,34 @@ export function usePreviewInteraction({
onClickToSource,
}: UsePreviewInteractionParams) {
const cycleRef = useRef<ClickCycleState | null>(null);
const lastDownRef = useRef<{ t: number; x: number; y: number } | null>(null);
const handlePreviewCanvasMouseDown = useCallback(
// fallow-ignore-next-line complexity
async (e: React.MouseEvent<HTMLDivElement>, options?: { preferClipAncestor?: boolean }) => {
if (!STUDIO_PREVIEW_SELECTION_ENABLED || captionEditMode || compositionLoading) return;
// Manual double-click detection (see DOUBLE_CLICK_MS): the first click
// re-renders the overlay so `e.detail` never reaches 2 on the canvas.
const downTs = Date.now();
const lastDown = lastDownRef.current;
const isDoubleClick =
e.detail >= 2 ||
(lastDown != null &&
downTs - lastDown.t < DOUBLE_CLICK_MS &&
Math.hypot(e.clientX - lastDown.x, e.clientY - lastDown.y) < DOUBLE_CLICK_RADIUS_PX);
lastDownRef.current = { t: downTs, x: e.clientX, y: e.clientY };
// Double-click a group → drill into it and select the child under the
// pointer (resolve with the group as the explicit drill-in scope, since the
// activeGroupElement state hasn't re-rendered yet within this handler).
if (e.detail >= 2 && !e.shiftKey) {
if (isDoubleClick && !e.shiftKey) {
const hit = await resolveDomSelectionFromPreviewPoint(e.clientX, e.clientY);
if (hit?.element.hasAttribute("data-hf-group")) {
e.preventDefault();
e.stopPropagation();
cycleRef.current = null;
trackStudioEvent("group", { action: "drill_in" });
setActiveGroupElement(hit.element);
const child = await resolveDomSelectionFromPreviewPoint(e.clientX, e.clientY, {
activeGroupElement: hit.element,
@@ -121,9 +141,21 @@ export function usePreviewInteraction({
}
// Fresh click — resolve topmost element
const nextSelection = await resolveDomSelectionFromPreviewPoint(e.clientX, e.clientY, {
let nextSelection = await resolveDomSelectionFromPreviewPoint(e.clientX, e.clientY, {
preferClipAncestor: options?.preferClipAncestor ?? false,
});
// A null result while drilled into a group means the click landed OUTSIDE that
// group (resolveGroupCapture → out-of-scope). Drill-in isn't sticky: exit it and
// re-resolve at the top level so this click selects whatever's there (or the
// group as a unit). Without this, a stale drill-in keeps selecting children and
// the "first click selects the group" expectation breaks.
if (!nextSelection) {
setActiveGroupElement(null);
nextSelection = await resolveDomSelectionFromPreviewPoint(e.clientX, e.clientY, {
preferClipAncestor: options?.preferClipAncestor ?? false,
activeGroupElement: null,
});
}
if (!nextSelection) {
cycleRef.current = null;
applyDomSelection(null, { revealPanel: false });