From 8a039f47ab27796b5fb4cbb132d6791d40b3b8f0 Mon Sep 17 00:00:00 2001 From: que01 Date: Mon, 31 Aug 2026 14:22:28 +0800 Subject: [PATCH] fix: keep the selection box on the crosswalk it is drawn around The box measured state.layers, which is the last compiled output and does not change while editing. The zebra is drawn from the preview, so it slid out from under its own box on every drag and only caught up after a recompile. Reading the preview when one exists puts them back on the same geometry. A null preview layer already means "back to baseline", which is what the fallback says. Co-Authored-By: Claude Opus 5 (1M context) --- workbench/client/src/App.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/workbench/client/src/App.tsx b/workbench/client/src/App.tsx index fa2f876..b379d14 100644 --- a/workbench/client/src/App.tsx +++ b/workbench/client/src/App.tsx @@ -188,9 +188,15 @@ function App() { if (!directEditEnabled || !element || !state) return null; const handle = crosswalkHandleFor(element, state.compiled.model.roads, editHandles); if (!handle?.editable) return null; - const bounds = orientedBoundsOf(groupMembers(state.layers.crosswalks?.features ?? [], element.elementId)); + // Read the preview when there is one. `state.layers` is the last *compiled* + // output and does not move during editing, so measuring the box there left it + // behind at the baseline while the zebra itself — drawn from the preview — + // slid out from under it. A null preview layer means "back to baseline", + // which is what the fallback expresses. + const drawn = preview?.crosswalks ?? state.layers.crosswalks; + const bounds = orientedBoundsOf(groupMembers(drawn?.features ?? [], element.elementId)); return bounds ? { handleId: handle.handleId, bounds } : null; - }, [element, editHandles, state]); + }, [element, editHandles, state, preview]); const sessionRef = useRef(null); if (directEditEnabled && !sessionRef.current) sessionRef.current = new EditSession(); // Per-frame drag feedback reaches the panel through this rather than through