@@ -25,11 +25,6 @@ impl Default for Document {
25
25
}
26
26
}
27
27
28
- fn split_path ( path : & [ LayerId ] ) -> Result < ( & [ LayerId ] , LayerId ) , DocumentError > {
29
- let ( id, path) = path. split_last ( ) . ok_or ( DocumentError :: InvalidPath ) ?;
30
- Ok ( ( path, * id) )
31
- }
32
-
33
28
impl Document {
34
29
/// Wrapper around render, that returns the whole document as a Response.
35
30
pub fn render_root ( & mut self ) -> String {
@@ -356,53 +351,53 @@ impl Document {
356
351
let transform = DAffine2 :: from_cols_array ( transform) ;
357
352
self . apply_transform_relative_to_viewport ( path, transform) ?;
358
353
self . mark_as_dirty ( path) ?;
359
- Some ( vec ! [ DocumentResponse :: DocumentChanged , DocumentResponse :: LayerChanged { path: path . clone ( ) } ] )
354
+ Some ( [ vec ! [ DocumentResponse :: DocumentChanged ] , update_thumbnails_upstream ( path) ] . concat ( ) )
360
355
}
361
356
Operation :: SetLayerTransformInViewport { path, transform } => {
362
357
let transform = DAffine2 :: from_cols_array ( transform) ;
363
358
self . set_transform_relative_to_viewport ( path, transform) ?;
364
359
self . mark_as_dirty ( path) ?;
365
- Some ( vec ! [ DocumentResponse :: DocumentChanged , DocumentResponse :: LayerChanged { path: path . clone ( ) } ] )
360
+ Some ( [ vec ! [ DocumentResponse :: DocumentChanged ] , update_thumbnails_upstream ( path) ] . concat ( ) )
366
361
}
367
362
Operation :: TransformLayerInScope { path, transform, scope } => {
368
363
let transform = DAffine2 :: from_cols_array ( transform) ;
369
364
let scope = DAffine2 :: from_cols_array ( scope) ;
370
365
self . transform_relative_to_scope ( path, Some ( scope) , transform) ?;
371
366
self . mark_as_dirty ( path) ?;
372
- Some ( vec ! [ DocumentResponse :: DocumentChanged , DocumentResponse :: LayerChanged { path: path . clone ( ) } ] )
367
+ Some ( [ vec ! [ DocumentResponse :: DocumentChanged ] , update_thumbnails_upstream ( path) ] . concat ( ) )
373
368
}
374
369
Operation :: SetLayerTransformInScope { path, transform, scope } => {
375
370
let transform = DAffine2 :: from_cols_array ( transform) ;
376
371
let scope = DAffine2 :: from_cols_array ( scope) ;
377
372
self . set_transform_relative_to_scope ( path, Some ( scope) , transform) ?;
378
373
self . mark_as_dirty ( path) ?;
379
- Some ( vec ! [ DocumentResponse :: DocumentChanged , DocumentResponse :: LayerChanged { path: path . clone ( ) } ] )
374
+ Some ( [ vec ! [ DocumentResponse :: DocumentChanged ] , update_thumbnails_upstream ( path) ] . concat ( ) )
380
375
}
381
376
Operation :: SetLayerTransform { path, transform } => {
382
377
let transform = DAffine2 :: from_cols_array ( transform) ;
383
378
let layer = self . layer_mut ( path) ?;
384
379
layer. transform = transform;
385
380
self . mark_as_dirty ( path) ?;
386
- Some ( vec ! [ DocumentResponse :: DocumentChanged , DocumentResponse :: LayerChanged { path: path . clone ( ) } ] )
381
+ Some ( [ vec ! [ DocumentResponse :: DocumentChanged ] , update_thumbnails_upstream ( path) ] . concat ( ) )
387
382
}
388
383
Operation :: ToggleVisibility { path } => {
389
384
self . mark_as_dirty ( path) ?;
390
385
if let Ok ( layer) = self . layer_mut ( path) {
391
386
layer. visible = !layer. visible ;
392
387
}
393
- Some ( vec ! [ DocumentResponse :: DocumentChanged , DocumentResponse :: LayerChanged { path: path . clone ( ) } ] )
388
+ Some ( [ vec ! [ DocumentResponse :: DocumentChanged ] , update_thumbnails_upstream ( path) ] . concat ( ) )
394
389
}
395
390
Operation :: SetLayerBlendMode { path, blend_mode } => {
396
391
self . mark_as_dirty ( path) ?;
397
392
self . layer_mut ( path) ?. blend_mode = * blend_mode;
398
393
399
- Some ( vec ! [ DocumentResponse :: DocumentChanged , DocumentResponse :: LayerChanged { path: path . clone ( ) } ] )
394
+ Some ( [ vec ! [ DocumentResponse :: DocumentChanged ] , update_thumbnails_upstream ( path) ] . concat ( ) )
400
395
}
401
396
Operation :: SetLayerOpacity { path, opacity } => {
402
397
self . mark_as_dirty ( path) ?;
403
398
self . layer_mut ( path) ?. opacity = * opacity;
404
399
405
- Some ( vec ! [ DocumentResponse :: DocumentChanged , DocumentResponse :: LayerChanged { path: path . clone ( ) } ] )
400
+ Some ( [ vec ! [ DocumentResponse :: DocumentChanged ] , update_thumbnails_upstream ( path) ] . concat ( ) )
406
401
}
407
402
Operation :: FillLayer { path, color } => {
408
403
let layer = self . layer_mut ( path) ?;
@@ -411,9 +406,25 @@ impl Document {
411
406
_ => return Err ( DocumentError :: NotAShape ) ,
412
407
}
413
408
self . mark_as_dirty ( path) ?;
414
- Some ( vec ! [ DocumentResponse :: DocumentChanged , DocumentResponse :: LayerChanged { path: path . clone ( ) } ] )
409
+ Some ( [ vec ! [ DocumentResponse :: DocumentChanged ] , update_thumbnails_upstream ( path) ] . concat ( ) )
415
410
}
416
411
} ;
417
412
Ok ( responses)
418
413
}
419
414
}
415
+
416
+ fn split_path ( path : & [ LayerId ] ) -> Result < ( & [ LayerId ] , LayerId ) , DocumentError > {
417
+ let ( id, path) = path. split_last ( ) . ok_or ( DocumentError :: InvalidPath ) ?;
418
+ Ok ( ( path, * id) )
419
+ }
420
+
421
+ fn update_thumbnails_upstream ( path : & [ LayerId ] ) -> Vec < DocumentResponse > {
422
+ let length = path. len ( ) ;
423
+ let mut responses = Vec :: with_capacity ( length) ;
424
+ for i in 0 ..length {
425
+ responses. push ( DocumentResponse :: LayerChanged {
426
+ path : path[ ( length - i) ..length] . to_vec ( ) ,
427
+ } ) ;
428
+ }
429
+ responses
430
+ }
0 commit comments