浏览代码

Period key works as pointer down / up (#377)

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

+ 58
- 2
packages/tldraw/src/state/TldrawApp.ts 查看文件

1437
         .map((shape) => {
1437
         .map((shape) => {
1438
           const parentShapeId = idsMap[shape.parentId]
1438
           const parentShapeId = idsMap[shape.parentId]
1439
 
1439
 
1440
-          console.log(shape)
1441
-
1442
           const copy = {
1440
           const copy = {
1443
             ...shape,
1441
             ...shape,
1444
             id: idsMap[shape.id],
1442
             id: idsMap[shape.id],
2500
 
2498
 
2501
   onKeyDown: TLKeyboardEventHandler = (key, info, e) => {
2499
   onKeyDown: TLKeyboardEventHandler = (key, info, e) => {
2502
     switch (e.key) {
2500
     switch (e.key) {
2501
+      case '.': {
2502
+        if (this.status === 'idle') {
2503
+          const { shiftKey, metaKey, altKey, ctrlKey, spaceKey } = this
2504
+
2505
+          this.onPointerDown(
2506
+            {
2507
+              target: 'canvas',
2508
+              pointerId: 0,
2509
+              origin: info.point,
2510
+              point: info.point,
2511
+              delta: [0, 0],
2512
+              pressure: 0.5,
2513
+              shiftKey,
2514
+              ctrlKey,
2515
+              metaKey,
2516
+              altKey,
2517
+              spaceKey,
2518
+            },
2519
+            {
2520
+              shiftKey,
2521
+              altKey,
2522
+              ctrlKey,
2523
+              pointerId: 0,
2524
+              clientX: info.point[0],
2525
+              clientY: info.point[1],
2526
+            } as unknown as React.PointerEvent<HTMLDivElement>
2527
+          )
2528
+        }
2529
+        break
2530
+      }
2503
       case 'Escape': {
2531
       case 'Escape': {
2504
         this.cancel()
2532
         this.cancel()
2505
         break
2533
         break
2531
     if (!info) return
2559
     if (!info) return
2532
 
2560
 
2533
     switch (e.key) {
2561
     switch (e.key) {
2562
+      case '.': {
2563
+        const { currentPoint, shiftKey, metaKey, altKey, ctrlKey, spaceKey } = this
2564
+
2565
+        this.onPointerUp(
2566
+          {
2567
+            target: 'canvas',
2568
+            pointerId: 0,
2569
+            origin: currentPoint,
2570
+            point: currentPoint,
2571
+            delta: [0, 0],
2572
+            pressure: 0.5,
2573
+            shiftKey,
2574
+            ctrlKey,
2575
+            metaKey,
2576
+            altKey,
2577
+            spaceKey,
2578
+          },
2579
+          {
2580
+            shiftKey,
2581
+            altKey,
2582
+            ctrlKey,
2583
+            pointerId: 0,
2584
+            clientX: currentPoint[0],
2585
+            clientY: currentPoint[1],
2586
+          } as unknown as React.PointerEvent<HTMLDivElement>
2587
+        )
2588
+        break
2589
+      }
2534
       case 'Meta': {
2590
       case 'Meta': {
2535
         this.metaKey = false
2591
         this.metaKey = false
2536
         break
2592
         break

+ 2
- 0
packages/tldraw/src/state/tools/ArrowTool/ArrowTool.ts 查看文件

9
   /* ----------------- Event Handlers ----------------- */
9
   /* ----------------- Event Handlers ----------------- */
10
 
10
 
11
   onPointerDown: TLPointerEventHandler = () => {
11
   onPointerDown: TLPointerEventHandler = () => {
12
+    if (this.status !== Status.Idle) return
13
+
12
     const {
14
     const {
13
       currentPoint,
15
       currentPoint,
14
       appState: { currentPageId, currentStyle },
16
       appState: { currentPageId, currentStyle },

+ 2
- 0
packages/tldraw/src/state/tools/DrawTool/DrawTool.ts 查看文件

9
   /* ----------------- Event Handlers ----------------- */
9
   /* ----------------- Event Handlers ----------------- */
10
 
10
 
11
   onPointerDown: TLPointerEventHandler = (info) => {
11
   onPointerDown: TLPointerEventHandler = (info) => {
12
+    if (this.status !== Status.Idle) return
13
+
12
     const {
14
     const {
13
       currentPoint,
15
       currentPoint,
14
       appState: { currentPageId, currentStyle },
16
       appState: { currentPageId, currentStyle },

+ 2
- 0
packages/tldraw/src/state/tools/EllipseTool/EllipseTool.ts 查看文件

9
   /* ----------------- Event Handlers ----------------- */
9
   /* ----------------- Event Handlers ----------------- */
10
 
10
 
11
   onPointerDown: TLPointerEventHandler = () => {
11
   onPointerDown: TLPointerEventHandler = () => {
12
+    if (this.status !== Status.Idle) return
13
+
12
     const {
14
     const {
13
       currentPoint,
15
       currentPoint,
14
       appState: { currentPageId, currentStyle },
16
       appState: { currentPageId, currentStyle },

+ 2
- 0
packages/tldraw/src/state/tools/EraseTool/EraseTool.ts 查看文件

18
   /* ----------------- Event Handlers ----------------- */
18
   /* ----------------- Event Handlers ----------------- */
19
 
19
 
20
   onPointerDown: TLPointerEventHandler = () => {
20
   onPointerDown: TLPointerEventHandler = () => {
21
+    if (this.status !== Status.Idle) return
22
+
21
     this.setStatus(Status.Pointing)
23
     this.setStatus(Status.Pointing)
22
   }
24
   }
23
 
25
 

+ 2
- 0
packages/tldraw/src/state/tools/LineTool/LineTool.ts 查看文件

9
   /* ----------------- Event Handlers ----------------- */
9
   /* ----------------- Event Handlers ----------------- */
10
 
10
 
11
   onPointerDown: TLPointerEventHandler = () => {
11
   onPointerDown: TLPointerEventHandler = () => {
12
+    if (this.status !== Status.Idle) return
13
+
12
     const {
14
     const {
13
       currentPoint,
15
       currentPoint,
14
       appState: { currentPageId, currentStyle },
16
       appState: { currentPageId, currentStyle },

+ 2
- 0
packages/tldraw/src/state/tools/RectangleTool/RectangleTool.ts 查看文件

9
   /* ----------------- Event Handlers ----------------- */
9
   /* ----------------- Event Handlers ----------------- */
10
 
10
 
11
   onPointerDown: TLPointerEventHandler = () => {
11
   onPointerDown: TLPointerEventHandler = () => {
12
+    if (this.status !== Status.Idle) return
13
+
12
     const {
14
     const {
13
       currentPoint,
15
       currentPoint,
14
       appState: { currentPageId, currentStyle },
16
       appState: { currentPageId, currentStyle },

+ 30
- 27
packages/tldraw/src/state/tools/SelectTool/SelectTool.ts 查看文件

237
   onPointerMove: TLPointerEventHandler = (info, e) => {
237
   onPointerMove: TLPointerEventHandler = (info, e) => {
238
     const { originPoint, currentPoint } = this.app
238
     const { originPoint, currentPoint } = this.app
239
 
239
 
240
-    if ((this.status === Status.SpacePanning && e.buttons === 1) || (this.status === Status.MiddleWheelPanning && e.buttons === 4)) {
240
+    if (
241
+      (this.status === Status.SpacePanning && e.buttons === 1) ||
242
+      (this.status === Status.MiddleWheelPanning && e.buttons === 4)
243
+    ) {
241
       this.app.onPan?.({ ...info, delta: Vec.neg(info.delta) }, e as unknown as WheelEvent)
244
       this.app.onPan?.({ ...info, delta: Vec.neg(info.delta) }, e as unknown as WheelEvent)
242
       return
245
       return
243
     }
246
     }
344
     if (e.buttons === 4) {
347
     if (e.buttons === 4) {
345
       this.setStatus(Status.MiddleWheelPanning)
348
       this.setStatus(Status.MiddleWheelPanning)
346
     }
349
     }
350
+
351
+    if (info.target === 'canvas' && this.status === Status.Idle) {
352
+      const { currentPoint } = this.app
353
+
354
+      if (info.spaceKey && e.buttons === 1) return
355
+
356
+      if (this.status === Status.Idle && info.altKey && info.shiftKey) {
357
+        this.setStatus(Status.ClonePainting)
358
+        this.clonePaint(currentPoint)
359
+        return
360
+      }
361
+
362
+      // Unless the user is holding shift or meta, clear the current selection
363
+      if (!info.shiftKey) {
364
+        this.app.onShapeBlur()
365
+
366
+        if (info.altKey && this.app.selectedIds.length > 0) {
367
+          this.app.duplicate(this.app.selectedIds, currentPoint)
368
+          return
369
+        }
370
+
371
+        this.selectNone()
372
+      }
373
+
374
+      this.setStatus(Status.PointingCanvas)
375
+    }
347
   }
376
   }
348
 
377
 
349
   onPointerUp: TLPointerEventHandler = (info, e) => {
378
   onPointerUp: TLPointerEventHandler = (info, e) => {
403
 
432
 
404
   // Canvas
433
   // Canvas
405
 
434
 
406
-  onPointCanvas: TLCanvasEventHandler = (info, e) => {
407
-    const { currentPoint } = this.app
408
-
409
-    if (info.spaceKey && e.buttons === 1) return
410
-
411
-    if (this.status === Status.Idle && info.altKey && info.shiftKey) {
412
-      this.setStatus(Status.ClonePainting)
413
-      this.clonePaint(currentPoint)
414
-      return
415
-    }
416
-
417
-    // Unless the user is holding shift or meta, clear the current selection
418
-    if (!info.shiftKey) {
419
-      this.app.onShapeBlur()
420
-
421
-      if (info.altKey && this.app.selectedIds.length > 0) {
422
-        this.app.duplicate(this.app.selectedIds, currentPoint)
423
-        return
424
-      }
425
-
426
-      this.selectNone()
427
-    }
428
-
429
-    this.setStatus(Status.PointingCanvas)
430
-  }
431
-
432
   onDoubleClickCanvas: TLCanvasEventHandler = () => {
435
   onDoubleClickCanvas: TLCanvasEventHandler = () => {
433
     // Needs debugging
436
     // Needs debugging
434
     // const { currentPoint } = this.app
437
     // const { currentPoint } = this.app

+ 8
- 7
packages/tldraw/src/test/TldrawTestApp.tsx 查看文件

73
       inputs.pointerDown(this.getPoint(options), id),
73
       inputs.pointerDown(this.getPoint(options), id),
74
       {} as React.PointerEvent
74
       {} as React.PointerEvent
75
     )
75
     )
76
-    this.onPointerDown(
77
-      inputs.pointerDown(this.getPoint(options), 'canvas'),
78
-      {} as React.PointerEvent
79
-    )
76
+    this.onPointerDown(inputs.pointerDown(this.getPoint(options), id), {} as React.PointerEvent)
80
     return this
77
     return this
81
   }
78
   }
82
 
79
 
83
   doubleClickBoundHandle = (id: TLBoundsHandle, options?: PointerOptions | number[]) => {
80
   doubleClickBoundHandle = (id: TLBoundsHandle, options?: PointerOptions | number[]) => {
81
+    this.onPointerDown(inputs.pointerDown(this.getPoint(options), id), {} as React.PointerEvent)
82
+    this.onPointerUp(inputs.pointerUp(this.getPoint(options), id), {} as React.PointerEvent)
83
+    this.onPointerDown(inputs.pointerDown(this.getPoint(options), id), {} as React.PointerEvent)
84
     this.onDoubleClickBoundsHandle(
84
     this.onDoubleClickBoundsHandle(
85
-      inputs.pointerDown(this.getPoint(options), id),
85
+      inputs.pointerUp(this.getPoint(options), id),
86
       {} as React.PointerEvent
86
       {} as React.PointerEvent
87
     )
87
     )
88
-    this.onPointerDown(
89
-      inputs.pointerDown(this.getPoint(options), 'canvas'),
88
+    this.onReleaseBoundsHandle?.(
89
+      inputs.pointerDown(this.getPoint(options), id),
90
       {} as React.PointerEvent
90
       {} as React.PointerEvent
91
     )
91
     )
92
+    this.onPointerUp?.(inputs.pointerUp(this.getPoint(options), id), {} as React.PointerEvent)
92
     return this
93
     return this
93
   }
94
   }
94
 
95
 

正在加载...
取消
保存