Browse Source

[fix] brush selection on groups (#335)

* select groups rather than grouped shapes

* Adds test
main
Steve Ruiz 3 years ago
parent
commit
adb680f8cf
No account linked to committer's email address

+ 1
- 1
packages/tldraw/package.json View File

@@ -49,7 +49,7 @@
49 49
     "@radix-ui/react-radio-group": "^0.1.1",
50 50
     "@radix-ui/react-tooltip": "^0.1.1",
51 51
     "@stitches/react": "^1.2.5",
52
-    "@tldraw/core": "^1.1.0",
52
+    "@tldraw/core": "^1.1.1",
53 53
     "@tldraw/intersect": "latest",
54 54
     "@tldraw/vec": "latest",
55 55
     "perfect-freehand": "^1.0.16",

+ 13
- 2
packages/tldraw/src/state/sessions/BrushSession/BrushSession.spec.ts View File

@@ -51,8 +51,6 @@ describe('Brush session', () => {
51 51
 
52 52
   it('when command is held, require the entire shape to be selected', () => {
53 53
     const app = new TldrawTestApp()
54
-      .loadDocument(mockDocument)
55
-      .selectNone()
56 54
       .loadDocument(mockDocument)
57 55
       .selectNone()
58 56
       .movePointer([-10, -10])
@@ -62,4 +60,17 @@ describe('Brush session', () => {
62 60
 
63 61
     expect(app.selectedIds.length).toBe(0)
64 62
   })
63
+
64
+  it('selects groups rather than grouped shapes', () => {
65
+    const app = new TldrawTestApp()
66
+      .loadDocument(mockDocument)
67
+      .selectAll()
68
+      .group()
69
+      .movePointer([-10, -10])
70
+      .startSession(SessionType.Brush)
71
+      .movePointer({ x: 100, y: 100 })
72
+      .stopPointing()
73
+
74
+    expect(app.selectedIds.length).toBe(1)
75
+  })
65 76
 })

+ 2
- 3
packages/tldraw/src/state/sessions/BrushSession/BrushSession.ts View File

@@ -15,6 +15,7 @@ export class BrushSession extends BaseSession {
15 15
 
16 16
   constructor(app: TldrawApp) {
17 17
     super(app)
18
+    const { currentPageId } = app
18 19
     this.initialSelectedIds = new Set(this.app.selectedIds)
19 20
     this.shapesToTest = this.app.shapes
20 21
       .filter(
@@ -22,7 +23,7 @@ export class BrushSession extends BaseSession {
22 23
           !(
23 24
             shape.isLocked ||
24 25
             shape.isHidden ||
25
-            shape.children !== undefined ||
26
+            shape.parentId !== currentPageId ||
26 27
             this.initialSelectedIds.has(shape.id) ||
27 28
             this.initialSelectedIds.has(shape.parentId)
28 29
           )
@@ -52,8 +53,6 @@ export class BrushSession extends BaseSession {
52 53
     const selectedIds = new Set(initialSelectedIds)
53 54
 
54 55
     shapesToTest.forEach(({ id, selectId }) => {
55
-      if (selectedIds.has(id)) return
56
-
57 56
       const { metaKey } = this.app
58 57
 
59 58
       const shape = this.app.getShape(id)

+ 2
- 1
packages/tldraw/tsconfig.json View File

@@ -8,7 +8,8 @@
8 8
     "rootDir": "src",
9 9
     "baseUrl": "src",
10 10
     "paths": {
11
-      "~*": ["./*"]
11
+      "~*": ["./*"],
12
+      "@tldraw/core": ["../core"]
12 13
     }
13 14
   },
14 15
   "typedocOptions": {

Loading…
Cancel
Save