@@ -27,16 +27,9 @@ import {
27
27
} from "../../hooks" ;
28
28
import { useTranslation } from "react-i18next" ;
29
29
import { useEventListener } from "usehooks-ts" ;
30
- import { areFieldsCompatible } from "../../utils/utils" ;
31
- import {
32
- getRectFromEndpoints ,
33
- isInsideRect ,
34
- areaRect ,
35
- noteRect ,
36
- tableRect ,
37
- pointIsInsideRect ,
38
- } from "../../utils/rect" ;
39
- import { State } from "../../data/constants" ;
30
+ import { areFieldsCompatible , getTableHeight } from "../../utils/utils" ;
31
+ import { getRectFromEndpoints , isInsideRect } from "../../utils/rect" ;
32
+ import { State , noteWidth } from "../../data/constants" ;
40
33
41
34
export default function Canvas ( ) {
42
35
const { t } = useTranslation ( ) ;
@@ -96,13 +89,14 @@ export default function Canvas() {
96
89
width : 0 ,
97
90
height : 0 ,
98
91
} ) ;
99
- const [ bulkSelectRectPts , setBulkSelectRectPts ] = useState ( {
92
+ const [ bulkSelectRect , setBulkSelectRect ] = useState ( {
100
93
x1 : 0 ,
101
94
y1 : 0 ,
102
95
x2 : 0 ,
103
96
y2 : 0 ,
104
97
show : false ,
105
98
ctrlKey : false ,
99
+ metaKey : false ,
106
100
} ) ;
107
101
// this is used to store the element that is clicked on
108
102
// at the moment, and shouldn't be a part of the state
@@ -113,15 +107,15 @@ export default function Canvas() {
113
107
} ;
114
108
115
109
const collectSelectedElements = ( ) => {
116
- const rect = getRectFromEndpoints ( bulkSelectRectPts ) ;
110
+ const rect = getRectFromEndpoints ( bulkSelectRect ) ;
117
111
const elements = [ ] ;
118
112
const shouldAddElement = ( elementRect , element ) => {
119
113
// if ctrl key is pressed, only add the elements that are not already selected
120
114
// can theoretically be optimized later if the selected elements is
121
115
// a map from id to element (after the ids are made unique)
122
116
return (
123
117
isInsideRect ( elementRect , rect ) &&
124
- ( ! bulkSelectRectPts . ctrlKey ||
118
+ ( ( ! bulkSelectRect . ctrlKey && ! bulkSelectRect . metaKey ) ||
125
119
! bulkSelectedElements . some ( ( el ) => isSameElement ( el , element ) ) )
126
120
) ;
127
121
} ;
@@ -135,7 +129,13 @@ export default function Canvas() {
135
129
currentCoords : { x : table . x , y : table . y } ,
136
130
initialCoords : { x : table . x , y : table . y } ,
137
131
} ;
138
- if ( shouldAddElement ( tableRect ( table , settings ) , element ) ) {
132
+ const tableRect = {
133
+ x : table . x ,
134
+ y : table . y ,
135
+ width : settings . tableWidth ,
136
+ height : getTableHeight ( table ) ,
137
+ } ;
138
+ if ( shouldAddElement ( tableRect , element ) ) {
139
139
elements . push ( element ) ;
140
140
}
141
141
} ) ;
@@ -149,7 +149,13 @@ export default function Canvas() {
149
149
currentCoords : { x : area . x , y : area . y } ,
150
150
initialCoords : { x : area . x , y : area . y } ,
151
151
} ;
152
- if ( shouldAddElement ( areaRect ( area ) , element ) ) {
152
+ const areaRect = {
153
+ x : area . x ,
154
+ y : area . y ,
155
+ width : area . width ,
156
+ height : area . height ,
157
+ } ;
158
+ if ( shouldAddElement ( areaRect , element ) ) {
153
159
elements . push ( element ) ;
154
160
}
155
161
} ) ;
@@ -163,12 +169,18 @@ export default function Canvas() {
163
169
currentCoords : { x : note . x , y : note . y } ,
164
170
initialCoords : { x : note . x , y : note . y } ,
165
171
} ;
166
- if ( shouldAddElement ( noteRect ( note ) , element ) ) {
172
+ const noteRect = {
173
+ x : note . x ,
174
+ y : note . y ,
175
+ width : noteWidth ,
176
+ height : note . height ,
177
+ } ;
178
+ if ( shouldAddElement ( noteRect , element ) ) {
167
179
elements . push ( element ) ;
168
180
}
169
181
} ) ;
170
182
171
- if ( bulkSelectRectPts . ctrlKey ) {
183
+ if ( bulkSelectRect . ctrlKey || bulkSelectRect . metaKey ) {
172
184
setBulkSelectedElements ( [ ...bulkSelectedElements , ...elements ] ) ;
173
185
} else {
174
186
setBulkSelectedElements ( elements ) ;
@@ -180,7 +192,7 @@ export default function Canvas() {
180
192
181
193
if ( ! e . isPrimary ) return ;
182
194
183
- if ( ! element . locked || ! e . ctrlKey ) {
195
+ if ( ! element . locked || ! ( e . ctrlKey || e . metaKey ) ) {
184
196
setSelectedElement ( ( prev ) => ( {
185
197
...prev ,
186
198
element : type ,
@@ -190,13 +202,13 @@ export default function Canvas() {
190
202
}
191
203
192
204
if ( element . locked ) {
193
- if ( ! e . ctrlKey ) {
205
+ if ( ! ( e . ctrlKey || e . metaKey ) ) {
194
206
setBulkSelectedElements ( [ ] ) ;
195
207
}
196
208
return ;
197
209
}
198
210
199
- setBulkSelectRectPts ( ( prev ) => ( {
211
+ setBulkSelectRect ( ( prev ) => ( {
200
212
...prev ,
201
213
show : false ,
202
214
} ) ) ;
@@ -214,7 +226,7 @@ export default function Canvas() {
214
226
isSameElement ( el , elementInBulk ) ,
215
227
) ;
216
228
217
- if ( e . ctrlKey ) {
229
+ if ( e . ctrlKey || e . metaKey ) {
218
230
if ( isSelected ) {
219
231
if ( bulkSelectedElements . length > 1 ) {
220
232
setBulkSelectedElements (
@@ -365,8 +377,8 @@ export default function Canvas() {
365
377
return ;
366
378
}
367
379
368
- if ( bulkSelectRectPts . show ) {
369
- setBulkSelectRectPts ( ( prev ) => ( {
380
+ if ( bulkSelectRect . show ) {
381
+ setBulkSelectRect ( ( prev ) => ( {
370
382
...prev ,
371
383
x2 : pointer . spaces . diagram . x ,
372
384
y2 : pointer . spaces . diagram . y ,
@@ -392,13 +404,14 @@ export default function Canvas() {
392
404
const isMouseMiddleButton = e . button === 1 ;
393
405
394
406
if ( isMouseLeftButton ) {
395
- setBulkSelectRectPts ( {
407
+ setBulkSelectRect ( {
396
408
x1 : pointer . spaces . diagram . x ,
397
409
y1 : pointer . spaces . diagram . y ,
398
410
x2 : pointer . spaces . diagram . x ,
399
411
y2 : pointer . spaces . diagram . y ,
400
412
show : elementPointerDown === null || ! elementPointerDown . element . locked ,
401
413
ctrlKey : e . ctrlKey ,
414
+ metaKey : e . metaKey ,
402
415
} ) ;
403
416
if ( elementPointerDown !== null ) {
404
417
handlePointerDownOnElement ( e , elementPointerDown ) ;
@@ -476,8 +489,8 @@ export default function Canvas() {
476
489
) ;
477
490
}
478
491
479
- if ( bulkSelectRectPts . show ) {
480
- setBulkSelectRectPts ( ( prev ) => ( {
492
+ if ( bulkSelectRect . show ) {
493
+ setBulkSelectRect ( ( prev ) => ( {
481
494
...prev ,
482
495
x2 : pointer . spaces . diagram . x ,
483
496
y2 : pointer . spaces . diagram . y ,
@@ -726,9 +739,9 @@ export default function Canvas() {
726
739
} }
727
740
/>
728
741
) ) }
729
- { bulkSelectRectPts . show && (
742
+ { bulkSelectRect . show && (
730
743
< rect
731
- { ...getRectFromEndpoints ( bulkSelectRectPts ) }
744
+ { ...getRectFromEndpoints ( bulkSelectRect ) }
732
745
stroke = "grey"
733
746
fill = "grey"
734
747
fillOpacity = { 0.15 }
0 commit comments