|
69 | 69 |
|
70 | 70 | /** Determine visible midpoint, if any **/ |
71 | 71 | const onPointerMove = (evt: PointerEvent) => { |
| 72 | + if (selectedCorner !== null || !midpoints.some(m => m.visible)) { |
| 73 | + visibleMidpoint = undefined; |
| 74 | + return; |
| 75 | + } |
| 76 | +
|
72 | 77 | const [px, py] = transform.elementToImage(evt.offsetX, evt.offsetY); |
73 | 78 |
|
74 | 79 | const getDistSq = (pt: number[]) => |
|
117 | 122 | // Drag, not click |
118 | 123 | if (performance.now() - lastHandleClick > CLICK_THRESHOLD) return; |
119 | 124 |
|
120 | | - // Click on a CORNER instantly selects and converts to curve |
121 | | - const { type } = geom.points[idx]; |
122 | | - |
123 | | - if (type === 'CORNER') { |
124 | | - selectedCorner = idx; |
| 125 | + const isSelected = selectedCorner === idx; |
125 | 126 |
|
| 127 | + // Clicking on a handle with alt key pressed toggles between corner/curve |
| 128 | + if (isAltPressed) { |
126 | 129 | const polyline = togglePolylineCorner(shape, idx, viewportScale); |
127 | 130 | dispatch('change', polyline); |
| 131 | +
|
| 132 | + // If was not selected, select it now |
| 133 | + if (!isSelected) { |
| 134 | + selectedCorner = idx; |
| 135 | + } |
128 | 136 | } else { |
129 | | - const isSelected = selectedCorner === idx; |
130 | 137 | if (isSelected) { |
131 | | - // If already selected, toggle to corner |
132 | | - const polyline = togglePolylineCorner(shape, idx,viewportScale); |
133 | | - dispatch('change', polyline); |
| 138 | + selectedCorner = null; |
134 | 139 | } else { |
135 | | - // Just select |
136 | 140 | selectedCorner = idx; |
137 | 141 | } |
138 | 142 | } |
@@ -446,6 +450,7 @@ const onAddPoint = (midpointIdx: number) => async (evt: PointerEvent) => { |
446 | 450 | x={pt.point[0]} |
447 | 451 | y={pt.point[1]} |
448 | 452 | scale={viewportScale} |
| 453 | + selected={selectedCorner === idx} |
449 | 454 | on:dblclick={onDoubleClick(idx)} |
450 | 455 | on:pointerenter={onEnterHandle} |
451 | 456 | on:pointerleave={onLeaveHandle} |
|
0 commit comments