Browse Source

Fix page zoom bug

main
Steve Ruiz 4 years ago
parent
commit
7e03adcd52
6 changed files with 24 additions and 6 deletions
  1. 1
    3
      components/canvas/selected.tsx
  2. 1
    1
      lib/shape-utils/arrow.tsx
  3. 2
    0
      lib/shape-utils/rectangle.tsx
  4. 4
    1
      state/hacks.ts
  5. 11
    1
      state/inputs.tsx
  6. 5
    0
      state/state.ts

+ 1
- 3
components/canvas/selected.tsx View File

@@ -64,13 +64,11 @@ export const ShapeOutline = memo(function ShapeOutline({ id }: { id: string }) {
64 64
 })
65 65
 
66 66
 const SelectIndicator = styled('path', {
67
-  zStrokeWidth: 1,
67
+  zStrokeWidth: 2,
68 68
   strokeLineCap: 'round',
69 69
   strokeLinejoin: 'round',
70 70
   stroke: '$selected',
71
-  fill: 'transparent',
72 71
   pointerEvents: 'none',
73
-  paintOrder: 'stroke fill markers',
74 72
 
75 73
   variants: {
76 74
     isLocked: {

+ 1
- 1
lib/shape-utils/arrow.tsx View File

@@ -135,7 +135,7 @@ const arrow = registerShapeUtils<ArrowShape>({
135 135
           <path
136 136
             d={getArrowArcPath(start, end, circle, bend)}
137 137
             fill="none"
138
-            strokeWidth={+style.strokeWidth * 1.85}
138
+            strokeWidth={(+style.strokeWidth * 1.85).toString()}
139 139
             strokeLinecap="round"
140 140
           />
141 141
           <path d={path} strokeWidth={+style.strokeWidth * 1.5} />

+ 2
- 0
lib/shape-utils/rectangle.tsx View File

@@ -51,6 +51,7 @@ const rectangle = registerShapeUtils<RectangleShape>({
51 51
     return (
52 52
       <g id={id}>
53 53
         <rect
54
+          className="hi"
54 55
           rx={radius}
55 56
           ry={radius}
56 57
           x={+styles.strokeWidth / 2}
@@ -58,6 +59,7 @@ const rectangle = registerShapeUtils<RectangleShape>({
58 59
           width={Math.max(0, size[0] + -styles.strokeWidth)}
59 60
           height={Math.max(0, size[1] + -styles.strokeWidth)}
60 61
           strokeWidth={0}
62
+          fill={styles.fill}
61 63
         />
62 64
         <path d={path} fill={styles.stroke} />
63 65
       </g>

+ 4
- 1
state/hacks.ts View File

@@ -81,7 +81,10 @@ export function fastPinchCamera(
81 81
   const p1 = screenToWorld(point, data)
82 82
   camera.point = vec.add(camera.point, vec.sub(p1, p0))
83 83
 
84
-  data.pageStates[data.currentPageId].camera = { ...camera }
84
+  const pageState = data.pageStates[data.currentPageId]
85
+  pageState.camera = { ...camera }
86
+
87
+  data.pageStates[data.currentPageId] = { ...pageState }
85 88
 
86 89
   state.forceData(Object.freeze(data))
87 90
 }

+ 11
- 1
state/inputs.tsx View File

@@ -9,6 +9,7 @@ class Inputs {
9 9
   activePointerId?: number
10 10
   lastPointerUpTime = 0
11 11
   points: Record<string, PointerInfo> = {}
12
+  lastPointer: PointerInfo
12 13
 
13 14
   touchStart(e: TouchEvent | React.TouchEvent, target: string) {
14 15
     const { shiftKey, ctrlKey, metaKey, altKey } = e
@@ -30,6 +31,7 @@ class Inputs {
30 31
     this.points[touch.identifier] = info
31 32
     this.activePointerId = touch.identifier
32 33
 
34
+    this.lastPointer = info
33 35
     return info
34 36
   }
35 37
 
@@ -55,6 +57,7 @@ class Inputs {
55 57
       this.points[touch.identifier] = info
56 58
     }
57 59
 
60
+    this.lastPointer = info
58 61
     return info
59 62
   }
60 63
 
@@ -76,6 +79,7 @@ class Inputs {
76 79
     this.points[e.pointerId] = info
77 80
     this.activePointerId = e.pointerId
78 81
 
82
+    this.lastPointer = info
79 83
     return info
80 84
   }
81 85
 
@@ -94,6 +98,7 @@ class Inputs {
94 98
       altKey,
95 99
     }
96 100
 
101
+    this.lastPointer = info
97 102
     return info
98 103
   }
99 104
 
@@ -117,6 +122,7 @@ class Inputs {
117 122
       this.points[e.pointerId] = info
118 123
     }
119 124
 
125
+    this.lastPointer = info
120 126
     return info
121 127
   }
122 128
 
@@ -143,6 +149,7 @@ class Inputs {
143 149
       this.lastPointerUpTime = Date.now()
144 150
     }
145 151
 
152
+    this.lastPointer = info
146 153
     return info
147 154
   }
148 155
 
@@ -158,7 +165,10 @@ class Inputs {
158 165
   }
159 166
 
160 167
   isDoubleClick() {
161
-    const { origin, point } = this.pointer
168
+    if (!this.lastPointer) return
169
+
170
+    const { origin, point } = this.lastPointer
171
+
162 172
     return (
163 173
       Date.now() - this.lastPointerUpTime < DOUBLE_CLICK_DURATION &&
164 174
       vec.dist(origin, point) < 8

+ 5
- 0
state/state.ts View File

@@ -319,7 +319,12 @@ const state = createState({
319 319
             },
320 320
             pointingBounds: {
321 321
               on: {
322
+                STOPPED_POINTING_BOUNDS: [],
322 323
                 STOPPED_POINTING: [
324
+                  {
325
+                    if: 'isPointingBounds',
326
+                    do: 'clearSelectedIds',
327
+                  },
323 328
                   {
324 329
                     if: 'isPressingShiftKey',
325 330
                     then: [

Loading…
Cancel
Save