Canvas: make double-click-to-plant work on desktop
Build image / build-and-push (push) Successful in 19s
Gadfly review (reusable) / review (pull_request) Successful in 8m43s
Adversarial Review (Gadfly) / review (pull_request) Successful in 8m43s

"Double-click a bed to plant it" has done nothing since the Organic rebuild:
track() captures the pointer on the SVG root, and pointer capture retargets
the compatibility click/dblclick events to the root, so the onDoubleClick
handler on each object's <g> never fired. A double-click only selected.

The double press is now detected in objDown itself — two presses on the
same object within 400 ms and 12 px — which capture cannot retarget. The
second press focuses the bed and starts no drag, so its pointerup has
nothing to select into Plot; a plop in an unfocused bed already delegates
to objDown, so double-clicking a plant focuses its bed too.

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
2026-08-23 03:12:13 -04:00
co-authored by Claude Fable 5
parent a37122fc77
commit 916b2989f5
+21 -1
View File
@@ -329,6 +329,16 @@ export const Canvas = forwardRef<
if (!drag.current) drag.current = { t: 'pan', sx: e.clientX, sy: e.clientY, tx: st.vp.tx, ty: st.vp.ty, moved: false, th: thresh(e) }
}
// The last press on an object, for double-click detection. Detected here
// rather than with onDoubleClick on the object's <g>: track() captures the
// pointer on the SVG root, and capture retargets the compatibility click
// and dblclick events to the root, so a dblclick handler on the object
// never fires — which is why "double-click a bed to plant it" did nothing
// from the Organic rebuild until this was noticed (2026-08-23).
const lastPress = useRef<{ id: number; at: number; x: number; y: number } | null>(null)
const DOUBLE_PRESS_MS = 400
const DOUBLE_PRESS_PX = 12
const objDown = (o: EditorObject) => (e: ReactPointerEvent) => {
e.stopPropagation()
track(e)
@@ -342,6 +352,17 @@ export const Canvas = forwardRef<
}
// Dimmed siblings stay inert inside a focused bed.
if (st.focusId != null && o.id !== st.focusId) return
const prev = lastPress.current
const now = performance.now()
lastPress.current = { id: o.id, at: now, x: e.clientX, y: e.clientY }
if (prev && prev.id === o.id && now - prev.at < DOUBLE_PRESS_MS && Math.hypot(e.clientX - prev.x, e.clientY - prev.y) < DOUBLE_PRESS_PX) {
// Second press of a double-click: focus the bed to plant it. No drag
// starts, so the matching pointerup has nothing to select into Plot.
lastPress.current = null
drag.current = null
if (o.plantable) focusObject(o)
return
}
if (!latest.current.canEdit) {
st.setSel({ type: 'object', id: o.id })
st.setTab('plot')
@@ -562,7 +583,6 @@ export const Canvas = forwardRef<
opacity={dim ? DIM_OBJECT : 1}
style={{ cursor: dim ? 'default' : canEdit ? 'grab' : 'pointer' }}
onPointerDown={objDown(o)}
onDoubleClick={o.plantable && !dim ? () => focusObject(o) : undefined}
>
{o.shape === 'circle' ? (
<ellipse rx={o.widthCm / 2} ry={o.heightCm / 2} {...common} />