Files
hyperframes/packages/studio/src/utils/studioDebug.ts
T
Miguel Angel Simon Sierra 1b5f50d579 fix(studio): shift-click adds the element under the pointer, not the last one hovered
Shift-click read the hover cache and used it without checking what it described.
That cache is filled asynchronously as the pointer moves, so passing over one
element on the way to another leaves it naming the element you left. The
shift-click then added THAT element, and because the same branch prevented the
default and set the suppression flags, the mousedown path that would have
resolved the point correctly never ran. Multi-select looked like it grabbed
things at random, or like it did nothing.

Reproduced on the canvas with a trace: hover #card, shift-click #dot-b, and the
group gained #card. Same gesture after: the guard rejects the cache, the
mousedown path resolves the point, and the group gains #dot-b.

The cache is still used when it is provably about the point clicked, including
when it names a clip ancestor of the element there, so the fast path survives for
the common case of clicking straight at something.

Adds `hf-select-debug` (localStorage, off by default) recording which selection
branch ran and what it decided, and pulls the flag/format shared with
`hf-reload-debug` into one place rather than copying it.
2026-08-07 19:38:12 -07:00

27 lines
1.0 KiB
TypeScript

// Opt-in diagnostic channels — one per question worth tracing, all off by
// default. Turn one on for the session with `localStorage.setItem("hf-<name>-debug",
// "1")` and reload, then grep the console for `[hf-<name>]`.
//
// These exist because the interesting failures here are decisions, not crashes:
// a preview that reloads when it should not, a shift-click that selects nothing.
// Nothing is thrown and nothing is logged by default, so without a trace of the
// decision the only way to find the cause is to guess.
type DebugLogger = (stage: string, data?: Record<string, unknown>) => void;
export function makeStudioDebugLogger(name: string): DebugLogger {
let enabled: boolean | null = null;
return (stage, data = {}) => {
if (enabled === null) {
try {
enabled = localStorage.getItem(`hf-${name}-debug`) === "1";
} catch {
enabled = false;
}
}
if (!enabled) return;
console.log(
`[hf-${name}] ${JSON.stringify({ stage, t: Math.round(performance.now()), ...data })}`,
);
};
}