浏览代码

[fix] brush selection on groups (#335)

* select groups rather than grouped shapes

* Adds test
main
Steve Ruiz 3 年前
父节点
当前提交
adb680f8cf
没有帐户链接到提交者的电子邮件

+ 1
- 1
packages/tldraw/package.json 查看文件

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

+ 13
- 2
packages/tldraw/src/state/sessions/BrushSession/BrushSession.spec.ts 查看文件

51
 
51
 
52
   it('when command is held, require the entire shape to be selected', () => {
52
   it('when command is held, require the entire shape to be selected', () => {
53
     const app = new TldrawTestApp()
53
     const app = new TldrawTestApp()
54
-      .loadDocument(mockDocument)
55
-      .selectNone()
56
       .loadDocument(mockDocument)
54
       .loadDocument(mockDocument)
57
       .selectNone()
55
       .selectNone()
58
       .movePointer([-10, -10])
56
       .movePointer([-10, -10])
62
 
60
 
63
     expect(app.selectedIds.length).toBe(0)
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 查看文件

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

+ 2
- 1
packages/tldraw/tsconfig.json 查看文件

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

正在加载...
取消
保存