From adb680f8cf4f13425b0a62758556502399efb657 Mon Sep 17 00:00:00 2001 From: Steve Ruiz Date: Sun, 21 Nov 2021 12:40:17 +0000 Subject: [PATCH] [fix] brush selection on groups (#335) * select groups rather than grouped shapes * Adds test --- packages/tldraw/package.json | 2 +- .../sessions/BrushSession/BrushSession.spec.ts | 15 +++++++++++++-- .../state/sessions/BrushSession/BrushSession.ts | 5 ++--- packages/tldraw/tsconfig.json | 3 ++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/packages/tldraw/package.json b/packages/tldraw/package.json index 072979631..3136a92c0 100644 --- a/packages/tldraw/package.json +++ b/packages/tldraw/package.json @@ -49,7 +49,7 @@ "@radix-ui/react-radio-group": "^0.1.1", "@radix-ui/react-tooltip": "^0.1.1", "@stitches/react": "^1.2.5", - "@tldraw/core": "^1.1.0", + "@tldraw/core": "^1.1.1", "@tldraw/intersect": "latest", "@tldraw/vec": "latest", "perfect-freehand": "^1.0.16", diff --git a/packages/tldraw/src/state/sessions/BrushSession/BrushSession.spec.ts b/packages/tldraw/src/state/sessions/BrushSession/BrushSession.spec.ts index b0af19c06..196bb49c2 100644 --- a/packages/tldraw/src/state/sessions/BrushSession/BrushSession.spec.ts +++ b/packages/tldraw/src/state/sessions/BrushSession/BrushSession.spec.ts @@ -51,8 +51,6 @@ describe('Brush session', () => { it('when command is held, require the entire shape to be selected', () => { const app = new TldrawTestApp() - .loadDocument(mockDocument) - .selectNone() .loadDocument(mockDocument) .selectNone() .movePointer([-10, -10]) @@ -62,4 +60,17 @@ describe('Brush session', () => { expect(app.selectedIds.length).toBe(0) }) + + it('selects groups rather than grouped shapes', () => { + const app = new TldrawTestApp() + .loadDocument(mockDocument) + .selectAll() + .group() + .movePointer([-10, -10]) + .startSession(SessionType.Brush) + .movePointer({ x: 100, y: 100 }) + .stopPointing() + + expect(app.selectedIds.length).toBe(1) + }) }) diff --git a/packages/tldraw/src/state/sessions/BrushSession/BrushSession.ts b/packages/tldraw/src/state/sessions/BrushSession/BrushSession.ts index 86215df47..8753a0ec1 100644 --- a/packages/tldraw/src/state/sessions/BrushSession/BrushSession.ts +++ b/packages/tldraw/src/state/sessions/BrushSession/BrushSession.ts @@ -15,6 +15,7 @@ export class BrushSession extends BaseSession { constructor(app: TldrawApp) { super(app) + const { currentPageId } = app this.initialSelectedIds = new Set(this.app.selectedIds) this.shapesToTest = this.app.shapes .filter( @@ -22,7 +23,7 @@ export class BrushSession extends BaseSession { !( shape.isLocked || shape.isHidden || - shape.children !== undefined || + shape.parentId !== currentPageId || this.initialSelectedIds.has(shape.id) || this.initialSelectedIds.has(shape.parentId) ) @@ -52,8 +53,6 @@ export class BrushSession extends BaseSession { const selectedIds = new Set(initialSelectedIds) shapesToTest.forEach(({ id, selectId }) => { - if (selectedIds.has(id)) return - const { metaKey } = this.app const shape = this.app.getShape(id) diff --git a/packages/tldraw/tsconfig.json b/packages/tldraw/tsconfig.json index 9b779f91c..c8a7d4c89 100644 --- a/packages/tldraw/tsconfig.json +++ b/packages/tldraw/tsconfig.json @@ -8,7 +8,8 @@ "rootDir": "src", "baseUrl": "src", "paths": { - "~*": ["./*"] + "~*": ["./*"], + "@tldraw/core": ["../core"] } }, "typedocOptions": {