A box selection picks up the wires and cables it crosses

A box that touches no parts selects every wire it crosses, so dragging
across the wires between parts marks them for bundling. Right to left
(green box) selects everything touched, parts and wires; left to right over
parts keeps selecting only wires fully inside, so Delete stays safe.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-10-21 11:08:32 +02:00
parent 29c32026d7
commit cf24578248
6 changed files with 46 additions and 4 deletions

View File

@ -20,6 +20,7 @@ Nuxt 4 (client-only editor, `ssr: false`), Tailwind CSS v4, Lucide icons via `@n
- Every circuit is a component. Its input and output nodes become its pins, ordered top to bottom. Double-click a component to open it.
- Lamps and hex displays inside a component show on its box, with their labels, lit by that instance's state. They are laid out in rows the way they sit inside. A checkbox in the inspector turns this off per component.
- The right panel has four tabs. **Selection**: settings of what you clicked (switches to it when you select something on an idle panel). **Circuit**: name, symbol, group, statistics, and where the transistors are (each kind of part with its count; click a line to select those parts). **Pins**: every input and output of the circuit in pin order, one line each, with its live value (click it to flip a switch, hold it for a button; panel rows are framed under their panel); rename in place (Enter goes to the next), "Number all" names a whole side from a pattern (D# → D0, D1, …), duplicate names are flagged, the target icon centres the canvas on a part. **Test**: the challenge or puzzle check and the truth table (opens by itself for a challenge). Display and sound preferences are in Settings (gear in the top bar). Both side panels fold away to a strip of icons (the panel icon in their tab row, or [ and ]).
- Box selection: a box that touches no parts selects every wire and cable it crosses (drag across the wires between parts to bundle them). Dragged right to left (green box) it selects everything it touches, parts and wires. Left to right over parts it takes those parts and only the wires lying fully inside, so Delete never catches unrelated wires passing through.
- Wiring many at once: select several parts and drag one wire from one of them to a pin of another part; the others follow onto that part's next pins, in position order (or use "Wire them all to" in the panel).
- Zooming out goes at least far enough to see the whole circuit, further for bigger circuits.
- Several selected parts are edited together: chips to narrow the selection by type, swap them all for another part, rename all top to bottom from a pattern, set every switch to 0 or 1 or flip each, one colour, one clock frequency or note size for all, line them up or spread them evenly, plus make component, connect one by one, unlink, duplicate, delete.

View File

@ -2252,3 +2252,8 @@ kbd {
.lane.c-blue { --w-on: #4dabff; --w-off: #2b4a6b; }
.lane.c-purple { --w-on: #b388ff; --w-off: #463768; }
.lane.c-pink { --w-on: #ff7ac6; --w-off: #673657; }
.box-select.crossing {
fill: rgb(61 220 132 / 0.08);
stroke: var(--on);
}

View File

@ -2,7 +2,7 @@
import { cableKeys } from '~/lib/logic/compile'
import { cableBits, GRID as G, pinPos, routeWire, type Pt, type Shape } from '~/lib/logic/geometry'
import type { CircuitNode, PanelRow, PinRef, Wire } from '~/lib/logic/types'
import { branchCorners, branchTo, moveCorner, moveSegment, segmentDrag, splitDrag } from '~/lib/logic/wires'
import { branchCorners, branchTo, moveCorner, moveSegment, routeTouchesBox, segmentDrag, splitDrag } from '~/lib/logic/wires'
import { circuitRoutes, findCrossings } from '~/lib/logic/routing'
import { seriesLinks } from '~/lib/logic/bulk'
import { LANE, ribbon } from '~/lib/logic/cables'
@ -488,7 +488,14 @@ function onPointerMove(e: PointerEvent) {
return n.x + b.x < x1 && n.x + b.x + b.w > x0 && n.y + b.y < y1 && n.y + b.y + b.h > y0
})
.map(n => n.id)
const wires = routes.value.filter(r => r.pts.every(([x, y]) => x >= x0 && x <= x1 && y >= y0 && y <= y1)).map(r => r.wire.id)
// Dragged right to left, or across wires without touching any part: every wire the box
// crosses. Otherwise only wires lying fully inside, so a box over some parts doesn't
// catch (and on Delete remove) unrelated wires passing through.
const box = { x0, y0, x1, y1 }
const crossing = w[0] < d.start[0] || !nodes.length
const wires = routes.value
.filter(r => (crossing ? routeTouchesBox(r.pts, box) : r.pts.every(([x, y]) => x >= x0 && x <= x1 && y >= y0 && y <= y1)))
.map(r => r.wire.id)
ed.selection.value = [...new Set([...d.nodes, ...nodes])]
ed.wireSel.value = [...new Set([...d.wires, ...wires])]
break
@ -825,6 +832,8 @@ const boxRect = computed(() => {
y: Math.min(d.start[1], d.cur[1]) * G,
width: Math.abs(d.cur[0] - d.start[0]) * G,
height: Math.abs(d.cur[1] - d.start[1]) * G,
// Right to left: everything the box touches (drawn green, as in CAD programs).
class: d.cur[0] < d.start[0] ? 'box-select crossing' : 'box-select',
}
})
@ -974,7 +983,7 @@ defineExpose({ fit, zoomAt })
<path v-if="cableGhost.line" :d="cableGhost.line" class="temp-wire" />
<EditorNodeView v-for="g in cableGhost.nodes" :key="g.id" :node="g" :shape="ed.shape(g)" :selected="false" ghost />
</template>
<rect v-if="boxRect" v-bind="boxRect" class="box-select" />
<rect v-if="boxRect" v-bind="boxRect" />
</g>
</svg>

View File

@ -16,7 +16,8 @@ const SHORTCUTS: [string, string][] = [
['Shift + click', 'Add parts or wires to the selection'],
['Arrow keys', 'Move the selection one step (Shift: four)'],
['Double-click a component', 'Open it and see inside'],
['Drag on empty space', 'Select several parts'],
['Drag on empty space', 'Select parts; across wires (no parts in the box) it selects every wire it crosses'],
['Drag right to left', 'Select everything the box touches, parts and wires (green box)'],
['Right or middle drag, Space + drag', 'Move the view'],
['Mouse wheel', 'Zoom'],
['N, I, O, L, B, C, H, T, P, X', 'Place NAND, input, output, lamp, button, clock, hex display, note, input panel, pixel'],

View File

@ -111,3 +111,18 @@ export function branchCorners(route: Pt[], i: number, at: Pt): Pt[] {
const c = pointOnSegment(route, i, at)
return simplify([...copy(route.slice(0, i + 1)), c]).slice(1)
}
/** True when any segment of the route passes through the box (edges included). */
export function routeTouchesBox(pts: Pt[], box: { x0: number; y0: number; x1: number; y1: number }): boolean {
for (let i = 0; i < pts.length - 1; i++) {
const [ax, ay] = pts[i]!
const [bx, by] = pts[i + 1]!
const lx = Math.min(ax, bx)
const hx = Math.max(ax, bx)
const ly = Math.min(ay, by)
const hy = Math.max(ay, by)
// Axis-aligned segment against an axis-aligned box: their extents overlap on both axes.
if (hx >= box.x0 && lx <= box.x1 && hy >= box.y0 && ly <= box.y1) return true
}
return false
}

View File

@ -192,3 +192,14 @@ describe('example counter face', () => {
}
})
})
describe('box selection of wires', () => {
it('finds wires that pass through a box, not only those inside it', async () => {
const { routeTouchesBox } = await import('../app/lib/logic/wires')
const route: Pt[] = [[0, 0], [10, 0], [10, 8], [20, 8]]
const box = { x0: 4, y0: -1, x1: 6, y1: 1 }
expect(routeTouchesBox(route, box)).toBe(true)
expect(routeTouchesBox(route, { x0: 12, y0: 1, x1: 18, y1: 6 })).toBe(false)
expect(routeTouchesBox(route, { x0: 9, y0: 3, x1: 11, y1: 4 })).toBe(true)
})
})