Bläddra i källkod

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

main
Steve Ruiz 3 år sedan
förälder
incheckning
3de6ef334a
Inget konto är kopplat till bidragsgivarens mejladress

+ 58
- 2
packages/tldraw/src/state/TldrawApp.ts Visa fil

@@ -1437,8 +1437,6 @@ export class TldrawApp extends StateManager<TDSnapshot> {
1437 1437
         .map((shape) => {
1438 1438
           const parentShapeId = idsMap[shape.parentId]
1439 1439
 
1440
-          console.log(shape)
1441
-
1442 1440
           const copy = {
1443 1441
             ...shape,
1444 1442
             id: idsMap[shape.id],
@@ -2500,6 +2498,36 @@ export class TldrawApp extends StateManager<TDSnapshot> {
2500 2498
 
2501 2499
   onKeyDown: TLKeyboardEventHandler = (key, info, e) => {
2502 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 2531
       case 'Escape': {
2504 2532
         this.cancel()
2505 2533
         break
@@ -2531,6 +2559,34 @@ export class TldrawApp extends StateManager<TDSnapshot> {
2531 2559
     if (!info) return
2532 2560
 
2533 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 2590
       case 'Meta': {
2535 2591
         this.metaKey = false
2536 2592
         break

+ 2
- 0
packages/tldraw/src/state/tools/ArrowTool/ArrowTool.ts Visa fil

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

+ 2
- 0
packages/tldraw/src/state/tools/DrawTool/DrawTool.ts Visa fil

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

+ 2
- 0
packages/tldraw/src/state/tools/EllipseTool/EllipseTool.ts Visa fil

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

+ 2
- 0
packages/tldraw/src/state/tools/EraseTool/EraseTool.ts Visa fil

@@ -18,6 +18,8 @@ export class EraseTool extends BaseTool {
18 18
   /* ----------------- Event Handlers ----------------- */
19 19
 
20 20
   onPointerDown: TLPointerEventHandler = () => {
21
+    if (this.status !== Status.Idle) return
22
+
21 23
     this.setStatus(Status.Pointing)
22 24
   }
23 25
 

+ 2
- 0
packages/tldraw/src/state/tools/LineTool/LineTool.ts Visa fil

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

+ 2
- 0
packages/tldraw/src/state/tools/RectangleTool/RectangleTool.ts Visa fil

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

+ 30
- 27
packages/tldraw/src/state/tools/SelectTool/SelectTool.ts Visa fil

@@ -237,7 +237,10 @@ export class SelectTool extends BaseTool<Status> {
237 237
   onPointerMove: TLPointerEventHandler = (info, e) => {
238 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 244
       this.app.onPan?.({ ...info, delta: Vec.neg(info.delta) }, e as unknown as WheelEvent)
242 245
       return
243 246
     }
@@ -344,6 +347,32 @@ export class SelectTool extends BaseTool<Status> {
344 347
     if (e.buttons === 4) {
345 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 378
   onPointerUp: TLPointerEventHandler = (info, e) => {
@@ -403,32 +432,6 @@ export class SelectTool extends BaseTool<Status> {
403 432
 
404 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 435
   onDoubleClickCanvas: TLCanvasEventHandler = () => {
433 436
     // Needs debugging
434 437
     // const { currentPoint } = this.app

+ 8
- 7
packages/tldraw/src/test/TldrawTestApp.tsx Visa fil

@@ -73,22 +73,23 @@ export class TldrawTestApp extends TldrawApp {
73 73
       inputs.pointerDown(this.getPoint(options), id),
74 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 77
     return this
81 78
   }
82 79
 
83 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 84
     this.onDoubleClickBoundsHandle(
85
-      inputs.pointerDown(this.getPoint(options), id),
85
+      inputs.pointerUp(this.getPoint(options), id),
86 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 90
       {} as React.PointerEvent
91 91
     )
92
+    this.onPointerUp?.(inputs.pointerUp(this.getPoint(options), id), {} as React.PointerEvent)
92 93
     return this
93 94
   }
94 95
 

Laddar…
Avbryt
Spara