From 5f5a4af59c5e8d34c6b589c12f788537f36b72d6 Mon Sep 17 00:00:00 2001 From: "Fabian @ Blax Software" Date: Wed, 28 Oct 2026 13:19:09 +0100 Subject: [PATCH] BF test bench docks when dragged onto a component, judged by its middle Co-Authored-By: Claude Opus 5.5 (1M context) --- app/components/editor/Canvas.vue | 2 +- app/composables/useEditor.ts | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/components/editor/Canvas.vue b/app/components/editor/Canvas.vue index ce143d6..b0273c8 100644 --- a/app/components/editor/Canvas.vue +++ b/app/components/editor/Canvas.vue @@ -1171,7 +1171,7 @@ function onPointerUp(e: PointerEvent) { ed.commit(false) } else if (d.moved) { ed.unplugMoved(new Set(d.orig.nodes.keys())) - ed.commit(false) + if (d.node.kind !== 'bench' || !ed.dropBench(d.node)) ed.commit(false) } else if (d.toggle && d.row) ed.toggleRow(d.node, d.row) else if (d.toggle && d.node.kind === 'keyboard') ed.typeInto(d.node.id) else if (d.toggle) ed.toggleInput(d.node) diff --git a/app/composables/useEditor.ts b/app/composables/useEditor.ts index 3b6a6fa..dda8ffd 100644 --- a/app/composables/useEditor.ts +++ b/app/composables/useEditor.ts @@ -913,7 +913,7 @@ function create() { if (p.kind === 'bench') { node.bench = { rows: [] } // Dropped on (or next to) a component: docks below it. - const chip = benchSpot(x, y) + const chip = benchSpot(node) if (chip) dockAt(node, chip) } // A new pixel is like the one placed last: building a colour screen, every pixel comes in colour. @@ -1450,8 +1450,11 @@ function create() { const benchOpen = ref(null) let benchTimer: ReturnType | undefined - /** The component a bench at this spot docks to: one whose box is under it or within two squares. */ - function benchSpot(x: number, y: number): CircuitNode | undefined { + /** The component a bench docks to: one whose box is under the bench's middle, or within two squares of it. */ + function benchSpot(bench: CircuitNode): CircuitNode | undefined { + const own = shapeOf(bench, getDef.value).body + const x = bench.x + own.x + own.w / 2 + const y = bench.y + own.y + own.h / 2 let best: CircuitNode | undefined let bestD = 2.01 for (const n of def.value.nodes) { @@ -1476,6 +1479,17 @@ function create() { bench.y = Math.ceil(chip.y + b.y + b.h + 1.5) } + /** A bench let go after a drag: onto a component, it docks there (elsewhere it stays as it was). */ + function dropBench(bench: CircuitNode) { + const chip = benchSpot(bench) + if (!chip || !bench.bench) return false + dockAt(bench, chip) + commit(false) + scheduleBenches() + notify(`Tests ${getDef.value(chip.chip ?? '')?.name ?? 'the component'}`) + return true + } + /** Docks a bench to a component of this circuit (or undocks it) and runs its tests. */ function dockBench(id: string, chipId: string | null) { const n = def.value.nodes.find(x => x.id === id) @@ -3104,6 +3118,7 @@ function create() { runBenchNow, setBench, dockBench, + dropBench, screens, keyQueues, devVersion,