@@ -17,6 +17,7 @@ import {
17
17
} from 'features/controlLayers/store/canvasSettingsSlice' ;
18
18
import {
19
19
buildEntityIsHiddenSelector ,
20
+ buildSelectIsSelected ,
20
21
selectBboxRect ,
21
22
selectCanvasSlice ,
22
23
selectEntity ,
@@ -165,6 +166,7 @@ export abstract class CanvasEntityAdapterBase<
165
166
} ;
166
167
167
168
selectIsHidden : Selector < RootState , boolean > ;
169
+ selectIsSelected : Selector < RootState , boolean > ;
168
170
169
171
/**
170
172
* The Konva nodes that make up the entity adapter:
@@ -249,6 +251,7 @@ export abstract class CanvasEntityAdapterBase<
249
251
this . state = state ;
250
252
251
253
this . selectIsHidden = buildEntityIsHiddenSelector ( this . entityIdentifier ) ;
254
+ this . selectIsSelected = buildSelectIsSelected ( this . entityIdentifier ) ;
252
255
253
256
/**
254
257
* There are a number of reason we may need to show or hide a layer:
@@ -257,6 +260,7 @@ export abstract class CanvasEntityAdapterBase<
257
260
* - Staging status changes and `isolatedStagingPreview` is enabled
258
261
* - Global filtering status changes and `isolatedFilteringPreview` is enabled
259
262
* - Global transforming status changes and `isolatedTransformingPreview` is enabled
263
+ * - The entity is selected or deselected (only selected and onscreen entities are rendered)
260
264
*/
261
265
this . subscriptions . add ( this . manager . stateApi . createStoreSubscription ( this . selectIsHidden , this . syncVisibility ) ) ;
262
266
this . subscriptions . add (
@@ -267,6 +271,7 @@ export abstract class CanvasEntityAdapterBase<
267
271
this . manager . stateApi . createStoreSubscription ( selectIsolatedTransformingPreview , this . syncVisibility )
268
272
) ;
269
273
this . subscriptions . add ( this . manager . stateApi . $transformingAdapter . listen ( this . syncVisibility ) ) ;
274
+ this . subscriptions . add ( this . manager . stateApi . createStoreSubscription ( this . selectIsSelected , this . syncVisibility ) ) ;
270
275
271
276
/**
272
277
* The tool preview may need to be updated when the entity is locked or disabled. For example, when we disable the
@@ -305,21 +310,8 @@ export abstract class CanvasEntityAdapterBase<
305
310
306
311
syncIsOnscreen = ( ) => {
307
312
const stageRect = this . manager . stage . getScaledStageRect ( ) ;
308
- const entityRect = this . transformer . $pixelRect . get ( ) ;
309
- const position = this . manager . stateApi . runSelector ( this . selectPosition ) ;
310
- if ( ! position ) {
311
- return ;
312
- }
313
- const entityRectRelativeToStage = {
314
- x : entityRect . x + position . x ,
315
- y : entityRect . y + position . y ,
316
- width : entityRect . width ,
317
- height : entityRect . height ,
318
- } ;
319
-
320
- const intersection = getRectIntersection ( stageRect , entityRectRelativeToStage ) ;
313
+ const isOnScreen = this . checkIntersection ( stageRect ) ;
321
314
const prevIsOnScreen = this . $isOnScreen . get ( ) ;
322
- const isOnScreen = intersection . width > 0 && intersection . height > 0 ;
323
315
this . $isOnScreen . set ( isOnScreen ) ;
324
316
if ( prevIsOnScreen !== isOnScreen ) {
325
317
this . log . trace ( `Moved ${ isOnScreen ? 'on-screen' : 'off-screen' } ` ) ;
@@ -329,25 +321,29 @@ export abstract class CanvasEntityAdapterBase<
329
321
330
322
syncIntersectsBbox = ( ) => {
331
323
const bboxRect = this . manager . stateApi . getBbox ( ) . rect ;
324
+ const intersectsBbox = this . checkIntersection ( bboxRect ) ;
325
+ const prevIntersectsBbox = this . $intersectsBbox . get ( ) ;
326
+ this . $intersectsBbox . set ( intersectsBbox ) ;
327
+ if ( prevIntersectsBbox !== intersectsBbox ) {
328
+ this . log . trace ( `Moved ${ intersectsBbox ? 'into bbox' : 'out of bbox' } ` ) ;
329
+ }
330
+ } ;
331
+
332
+ checkIntersection = ( rect : Rect ) : boolean => {
332
333
const entityRect = this . transformer . $pixelRect . get ( ) ;
333
334
const position = this . manager . stateApi . runSelector ( this . selectPosition ) ;
334
335
if ( ! position ) {
335
- return ;
336
+ return false ;
336
337
}
337
338
const entityRectRelativeToStage = {
338
339
x : entityRect . x + position . x ,
339
340
y : entityRect . y + position . y ,
340
341
width : entityRect . width ,
341
342
height : entityRect . height ,
342
343
} ;
343
-
344
- const intersection = getRectIntersection ( bboxRect , entityRectRelativeToStage ) ;
345
- const prevIntersectsBbox = this . $intersectsBbox . get ( ) ;
346
- const intersectsBbox = intersection . width > 0 && intersection . height > 0 ;
347
- this . $intersectsBbox . set ( intersectsBbox ) ;
348
- if ( prevIntersectsBbox !== intersectsBbox ) {
349
- this . log . trace ( `Moved ${ intersectsBbox ? 'into bbox' : 'out of bbox' } ` ) ;
350
- }
344
+ const intersection = getRectIntersection ( rect , entityRectRelativeToStage ) ;
345
+ const doesIntersect = intersection . width > 0 && intersection . height > 0 ;
346
+ return doesIntersect ;
351
347
} ;
352
348
353
349
initialize = async ( ) => {
0 commit comments