From fadb6fca1b736feaab8cfe5d3d482617ab67579c Mon Sep 17 00:00:00 2001 From: Michael Pearce Date: Wed, 25 Nov 2026 21:55:17 -0800 Subject: [PATCH 1/6] (feat) Select a range of parts with Shift+click in Parts --- src/components/Dialogs.tsx | 3 ++- src/components/PartsPanel.tsx | 28 ++++++++++++++++++++++++-- src/core/part-tree.ts | 19 +++++++++++++++++ src/core/store.ts | 9 +++++++++ tests/e2e/alignment-visibility.spec.ts | 2 +- tests/e2e/free-transform.spec.ts | 2 +- tests/e2e/inspection.spec.ts | 6 +++--- tests/e2e/parts-panel.spec.ts | 26 ++++++++++++++++++++++++ tests/e2e/shortcuts.spec.ts | 6 +++--- tests/e2e/transforms.spec.ts | 2 +- tests/e2e/workbench.spec.ts | 2 +- 11 files changed, 92 insertions(+), 13 deletions(-) create mode 100644 src/core/part-tree.ts create mode 100644 tests/e2e/parts-panel.spec.ts diff --git a/src/components/Dialogs.tsx b/src/components/Dialogs.tsx index f792c0a..c362f03 100644 --- a/src/components/Dialogs.tsx +++ b/src/components/Dialogs.tsx @@ -631,7 +631,8 @@ function HelpDialog() { ['Fine move / rotate / scale', 'Hold Shift while dragging · 10× finer'], ['Pan', 'Right drag or Shift + left drag'], ['Zoom', 'Scroll / pinch · tune in Preferences'], - ['Select multiple', 'Shift / Ctrl / ⌘ + click'], + ['Select multiple', 'Ctrl / ⌘ + click · Shift + click in the viewport'], + ['Select a range of parts', 'Shift + click in Parts'], ['Select all components', key('selectAll')], ['Deselect all', keys('deselect', 'cancel')], ['Copy / Cut / Paste components', keys('copy', 'cut', 'paste')], diff --git a/src/components/PartsPanel.tsx b/src/components/PartsPanel.tsx index 18e2eb8..5364179 100644 --- a/src/components/PartsPanel.tsx +++ b/src/components/PartsPanel.tsx @@ -1,4 +1,5 @@ -import { useMemo, useState } from 'react'; +import { useMemo, useRef, useState } from 'react'; +import type { MouseEvent } from 'react'; import { ArrowDownToLine, Box, @@ -21,6 +22,7 @@ import { import { useEditor } from '../core/store'; import { referencePlanes } from '../core/references'; import { triangleCount } from '../core/geometry'; +import { selectionRange } from '../core/part-tree'; import { distinctColors, swatchBackground, swatchColors } from '../core/appearance'; import { IconButton } from './ui'; import { ConstraintList } from './ConstraintList'; @@ -37,6 +39,28 @@ export function PartsPanel({ onClose }: { onClose: () => void }) { [query, setQuery] = useState(''), [expanded, setExpanded] = useState(true); const filtered = scene.parts.filter((p) => p.name.toLowerCase().includes(query.toLowerCase())); + // Where Shift+click ranges from: the last part clicked here, or else the last one selected. + const anchor = useRef(null); + const choose = (event: MouseEvent, id: string) => { + const state = useEditor.getState(); + if (event.shiftKey) { + const from = + anchor.current && state.selected.includes(anchor.current) + ? anchor.current + : state.selected.at(-1); + anchor.current = from ?? id; + state.selectParts( + selectionRange( + filtered.map((part) => part.id), + from, + [id], + ), + ); + return; + } + anchor.current = id; + state.select(id, event.metaKey || event.ctrlKey); + }; const distinct = useMemo(() => distinctColors(scene.parts), [scene.parts]); const triangles = scene.parts.reduce((sum, p) => sum + triangleCount(p.geometry), 0); return ( @@ -103,7 +127,7 @@ export function PartsPanel({ onClose }: { onClose: () => void }) { {expanded - ? filtered.map((part) => ( -
- -
- +
+ + +
-
- )) + ); + }) : null} {!filtered.length ? (
diff --git a/tests/e2e/parts-panel.spec.ts b/tests/e2e/parts-panel.spec.ts index 447d754..ef44e1e 100644 --- a/tests/e2e/parts-panel.spec.ts +++ b/tests/e2e/parts-panel.spec.ts @@ -24,3 +24,25 @@ test('Shift+click selects a range of parts and Ctrl or ⌘ adds one', async ({ p await row(page, 'Left arm').click({ modifiers: ['Shift'] }); expect(await selectedNames(page)).toEqual(['Left arm', 'Right shoulder', 'Right arm']); }); + +test('the eye on a selected row shows or hides every selected part', async ({ page }) => { + const muted = () => + page + .locator('.part-row.muted .part-select') + .evaluateAll((rows) => rows.map((row) => row.getAttribute('title'))); + await row(page, 'Torso shell').click(); + await row(page, 'Optics & head').click({ modifiers: ['Shift'] }); + await page + .getByRole('button', { name: 'Hide Power pack and 2 more selected', exact: true }) + .click(); + expect(await muted()).toEqual(['Torso shell', 'Power pack', 'Optics & head']); + // A row outside the selection changes on its own. + await page.getByRole('button', { name: 'Hide Right arm', exact: true }).click(); + expect(await muted()).toEqual(['Torso shell', 'Power pack', 'Optics & head', 'Right arm']); + await page + .getByRole('button', { name: 'Show Torso shell and 2 more selected', exact: true }) + .click(); + expect(await muted()).toEqual(['Right arm']); + await page.keyboard.press('ControlOrMeta+z'); + expect(await muted()).toEqual(['Torso shell', 'Power pack', 'Optics & head', 'Right arm']); +}); From f38957a7540a82d99762c433064af38406377ffb Mon Sep 17 00:00:00 2001 From: Michael Pearce Date: Wed, 25 Nov 2026 22:03:48 -0800 Subject: [PATCH 3/6] (feat) Group and ungroup parts --- mcp/session.ts | 8 +- src/components/Dialogs.tsx | 1 + src/components/EditorContextMenu.tsx | 5 + src/components/PartsPanel.tsx | 246 ++++++++++++++++++--------- src/components/Viewport.tsx | 11 +- src/core/clipboard.ts | 63 ++++++- src/core/commands.ts | 15 ++ src/core/keybindings.ts | 2 + src/core/part-tree.ts | 145 ++++++++++++++++ src/core/scene-file.ts | 28 ++- src/core/store.ts | 59 +++++-- src/core/sync.ts | 23 ++- src/core/types.ts | 12 ++ src/styles.css | 38 +++++ tests/e2e/parts-panel.spec.ts | 73 ++++++++ tests/unit/cad-constraints.test.ts | 2 +- tests/unit/commands.test.ts | 2 +- tests/unit/part-groups.test.ts | 244 ++++++++++++++++++++++++++ 18 files changed, 861 insertions(+), 116 deletions(-) create mode 100644 tests/unit/part-groups.test.ts diff --git a/mcp/session.ts b/mcp/session.ts index 3a9d628..bd53e37 100644 --- a/mcp/session.ts +++ b/mcp/session.ts @@ -12,7 +12,7 @@ import { solveAlignment } from '../src/core/alignment'; import { evaluateBoolean } from '../src/core/boolean'; import type { ClipReport } from '../src/core/clipping'; import type { BooleanOperation } from '../src/core/boolean'; -import { captureComponents, instantiateComponents } from '../src/core/clipboard'; +import { addedGroups, captureComponents, instantiateComponents } from '../src/core/clipboard'; import { anchorError, isJointConnected } from '../src/core/constraints'; import { export3mf, @@ -724,7 +724,10 @@ export class Session { transform = step.clone().multiply(transform); const scene = editor().scene; const clipboard = { ...captureComponents(scene, sources), nextOffset: 0 }; - const copies = instantiateComponents(clipboard, [...scene.parts, ...added]); + const copies = instantiateComponents(clipboard, { + parts: [...scene.parts, ...added], + groups: scene.groups, + }); const ids = new Map(); const parts = copies.parts.map((part, i) => { const name = spec.names?.[added.length + i] ?? part.name; @@ -770,6 +773,7 @@ export class Session { parts: [...scene.parts, ...parts], joints: [...scene.joints, ...joints], constraints: [...(scene.constraints ?? []), ...constraints], + ...addedGroups(scene, copies.groups), }); added.push(...parts); } diff --git a/src/components/Dialogs.tsx b/src/components/Dialogs.tsx index c362f03..fc46926 100644 --- a/src/components/Dialogs.tsx +++ b/src/components/Dialogs.tsx @@ -659,6 +659,7 @@ function HelpDialog() { ['New assembly / Import', keys('new', 'import')], ['Export', key('export')], ['Duplicate', key('duplicate')], + ['Group / Ungroup', keys('group', 'ungroup')], ['Delete unlocked parts', key('delete')], ['Finish / Cancel tool', keys('apply', 'cancel')], ['Exit camera tool', `${key('cancel')} (keeps picked pairs)`], diff --git a/src/components/EditorContextMenu.tsx b/src/components/EditorContextMenu.tsx index d8172fa..cffd4f5 100644 --- a/src/components/EditorContextMenu.tsx +++ b/src/components/EditorContextMenu.tsx @@ -10,6 +10,7 @@ import { EyeOff, Focus, GitMerge, + Group, Import, Layers2, Link2, @@ -25,6 +26,7 @@ import { ScanLine, Scissors, Trash2, + Ungroup, UnlockKeyhole, } from 'lucide-react'; import { contactBrush, activeBrush } from '../core/editor-brush'; @@ -49,6 +51,8 @@ const icons = { duplicate: Copy, rename: Pencil, delete: Trash2, + group: Group, + ungroup: Ungroup, move: Move3D, rotate: Rotate3D, scale: Scaling, @@ -178,6 +182,7 @@ function OpenContextMenu({ ? [ ['cut', 'copy', 'paste', 'duplicate'], ['rename', 'delete'], + ['group', 'ungroup'], ['focus', 'pivot', 'align', 'paint', 'joint', 'merge', 'inspect'], ['isolate', 'isolateNearby'], ['hide', 'hideOthers', unlocked ? 'lock' : 'unlock', 'showAll'], diff --git a/src/components/PartsPanel.tsx b/src/components/PartsPanel.tsx index f292670..9cd5d5a 100644 --- a/src/components/PartsPanel.tsx +++ b/src/components/PartsPanel.tsx @@ -1,4 +1,4 @@ -import { useMemo, useRef, useState } from 'react'; +import { Fragment, useMemo, useRef, useState } from 'react'; import type { MouseEvent } from 'react'; import { ArrowDownToLine, @@ -10,6 +10,7 @@ import { Eye, EyeOff, FolderOpen, + Group, Link2, LockKeyhole, Plus, @@ -22,7 +23,9 @@ import { import { useEditor } from '../core/store'; import { referencePlanes } from '../core/references'; import { triangleCount } from '../core/geometry'; -import { selectionRange } from '../core/part-tree'; +import { partTree, selectionRange, treeOrder } from '../core/part-tree'; +import type { PartTreeEntry } from '../core/part-tree'; +import type { Part } from '../core/types'; import { distinctColors, swatchBackground, swatchColors } from '../core/appearance'; import { IconButton } from './ui'; import { ConstraintList } from './ConstraintList'; @@ -38,31 +41,167 @@ export function PartsPanel({ onClose }: { onClose: () => void }) { const [tab, setTab] = useState<'parts' | 'joints' | 'constraints'>('parts'), [query, setQuery] = useState(''), [expanded, setExpanded] = useState(true); - const filtered = scene.parts.filter((p) => p.name.toLowerCase().includes(query.toLowerCase())); + const tree = useMemo(() => partTree(scene, query), [scene, query]); + const [collapsed, setCollapsed] = useState>(() => new Set()), + [renaming, setRenaming] = useState(null); + const cancelRename = useRef(false); // Where Shift+click ranges from: the last part clicked here, or else the last one selected. const anchor = useRef(null); - const choose = (event: MouseEvent, id: string) => { + /** Clicks a part, or a group with these parts. */ + const choose = (event: MouseEvent, ids: string[]) => { const state = useEditor.getState(); if (event.shiftKey) { const from = anchor.current && state.selected.includes(anchor.current) ? anchor.current : state.selected.at(-1); - anchor.current = from ?? id; - state.selectParts( - selectionRange( - filtered.map((part) => part.id), - from, - [id], - ), - ); + anchor.current = from ?? ids[0]; + state.selectParts(selectionRange(treeOrder(tree), from, ids)); return; } - anchor.current = id; - state.select(id, event.metaKey || event.ctrlKey); + anchor.current = ids[0]; + if (event.metaKey || event.ctrlKey) state.select(ids[0], true, ids.length > 1); + else state.selectParts(ids); }; const distinct = useMemo(() => distinctColors(scene.parts), [scene.parts]); const triangles = scene.parts.reduce((sum, p) => sum + triangleCount(p.geometry), 0); + const partRow = (part: Part, inGroup: boolean) => { + // On a row of a larger selection, the eye shows or hides the selection. + const selectedRow = selected.length > 1 && selected.includes(part.id); + return ( +
+ +
+ + +
+
+ ); + }; + const groupRow = ({ group, parts }: Extract) => { + const ids = parts.map((part) => part.id); + const whole = ids.every((id) => selected.includes(id)); + const open = !collapsed.has(group.id); + const visible = parts.some((part) => part.visible); + // Like a part's eye: on a group that is part of a larger selection, it acts on the selection. + const others = whole ? selected.length - ids.length : 0; + const rename = (name: string) => { + if (!cancelRename.current) useEditor.getState().renameGroup(group.id, name); + cancelRename.current = false; + setRenaming(null); + }; + return ( +
isolated.includes(id)) ? 'outside-isolation' : ''}`} + onContextMenu={() => { + if (!whole) useEditor.getState().selectParts(ids); + }} + > + + + {renaming === group.id ? ( + e.target.select()} + onBlur={(e) => rename(e.target.value)} + onKeyDown={(e) => { + if (e.key === 'Escape') cancelRename.current = true; + if (e.key === 'Enter' || e.key === 'Escape') e.currentTarget.blur(); + }} + /> + ) : ( + + )} +
+ +
+
+ ); + }; return (