@@ -31,6 +31,14 @@ function copyShape(state: TrackedShape, data: Partial<TrackedShape> = {}): Track
31
31
} ;
32
32
}
33
33
34
+ function computeNewSource ( currentSource : Source ) : Source {
35
+ if ( [ Source . AUTO , Source . SEMI_AUTO ] . includes ( currentSource ) ) {
36
+ return Source . SEMI_AUTO ;
37
+ }
38
+
39
+ return Source . MANUAL ;
40
+ }
41
+
34
42
export interface BasicInjection {
35
43
labels : Record < number , Label > ;
36
44
groups : { max : number } ;
@@ -596,7 +604,7 @@ export class Shape extends Drawn {
596
604
const undoRotation = this . rotation ;
597
605
const redoRotation = rotation ;
598
606
const undoSource = this . source ;
599
- const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : Source . MANUAL ;
607
+ const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : computeNewSource ( this . source ) ;
600
608
601
609
this . history . do (
602
610
HistoryActions . CHANGED_ROTATION ,
@@ -622,7 +630,7 @@ export class Shape extends Drawn {
622
630
const undoPoints = this . points ;
623
631
const redoPoints = points ;
624
632
const undoSource = this . source ;
625
- const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : Source . MANUAL ;
633
+ const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : computeNewSource ( this . source ) ;
626
634
627
635
this . history . do (
628
636
HistoryActions . CHANGED_POINTS ,
@@ -648,7 +656,7 @@ export class Shape extends Drawn {
648
656
const undoOccluded = this . occluded ;
649
657
const redoOccluded = occluded ;
650
658
const undoSource = this . source ;
651
- const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : Source . MANUAL ;
659
+ const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : computeNewSource ( this . source ) ;
652
660
653
661
this . history . do (
654
662
HistoryActions . CHANGED_OCCLUDED ,
@@ -674,7 +682,7 @@ export class Shape extends Drawn {
674
682
const undoOutside = this . outside ;
675
683
const redoOutside = outside ;
676
684
const undoSource = this . source ;
677
- const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : Source . MANUAL ;
685
+ const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : computeNewSource ( this . source ) ;
678
686
679
687
this . history . do (
680
688
HistoryActions . CHANGED_OCCLUDED ,
@@ -700,7 +708,7 @@ export class Shape extends Drawn {
700
708
const undoZOrder = this . zOrder ;
701
709
const redoZOrder = zOrder ;
702
710
const undoSource = this . source ;
703
- const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : Source . MANUAL ;
711
+ const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : computeNewSource ( this . source ) ;
704
712
705
713
this . history . do (
706
714
HistoryActions . CHANGED_ZORDER ,
@@ -1179,7 +1187,7 @@ export class Track extends Drawn {
1179
1187
protected saveRotation ( rotation : number , frame : number ) : void {
1180
1188
const wasKeyframe = frame in this . shapes ;
1181
1189
const undoSource = this . source ;
1182
- const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : Source . MANUAL ;
1190
+ const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : computeNewSource ( this . source ) ;
1183
1191
const undoShape = wasKeyframe ? this . shapes [ frame ] : undefined ;
1184
1192
const redoShape = wasKeyframe ?
1185
1193
{ ...this . shapes [ frame ] , rotation } : copyShape ( this . get ( frame ) , { rotation } ) ;
@@ -1199,7 +1207,7 @@ export class Track extends Drawn {
1199
1207
protected savePoints ( points : number [ ] , frame : number ) : void {
1200
1208
const wasKeyframe = frame in this . shapes ;
1201
1209
const undoSource = this . source ;
1202
- const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : Source . MANUAL ;
1210
+ const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : computeNewSource ( this . source ) ;
1203
1211
const undoShape = wasKeyframe ? this . shapes [ frame ] : undefined ;
1204
1212
const redoShape = wasKeyframe ?
1205
1213
{ ...this . shapes [ frame ] , points } : copyShape ( this . get ( frame ) , { points } ) ;
@@ -1219,7 +1227,7 @@ export class Track extends Drawn {
1219
1227
protected saveOutside ( frame : number , outside : boolean ) : void {
1220
1228
const wasKeyframe = frame in this . shapes ;
1221
1229
const undoSource = this . source ;
1222
- const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : Source . MANUAL ;
1230
+ const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : computeNewSource ( this . source ) ;
1223
1231
const undoShape = wasKeyframe ? this . shapes [ frame ] : undefined ;
1224
1232
const redoShape = wasKeyframe ?
1225
1233
{ ...this . shapes [ frame ] , outside } :
@@ -1240,7 +1248,7 @@ export class Track extends Drawn {
1240
1248
protected saveOccluded ( occluded : boolean , frame : number ) : void {
1241
1249
const wasKeyframe = frame in this . shapes ;
1242
1250
const undoSource = this . source ;
1243
- const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : Source . MANUAL ;
1251
+ const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : computeNewSource ( this . source ) ;
1244
1252
const undoShape = wasKeyframe ? this . shapes [ frame ] : undefined ;
1245
1253
const redoShape = wasKeyframe ?
1246
1254
{ ...this . shapes [ frame ] , occluded } :
@@ -1261,7 +1269,7 @@ export class Track extends Drawn {
1261
1269
protected saveZOrder ( zOrder : number , frame : number ) : void {
1262
1270
const wasKeyframe = frame in this . shapes ;
1263
1271
const undoSource = this . source ;
1264
- const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : Source . MANUAL ;
1272
+ const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : computeNewSource ( this . source ) ;
1265
1273
const undoShape = wasKeyframe ? this . shapes [ frame ] : undefined ;
1266
1274
const redoShape = wasKeyframe ?
1267
1275
{ ...this . shapes [ frame ] , zOrder } :
@@ -1287,7 +1295,7 @@ export class Track extends Drawn {
1287
1295
}
1288
1296
1289
1297
const undoSource = this . source ;
1290
- const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : Source . MANUAL ;
1298
+ const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : computeNewSource ( this . source ) ;
1291
1299
const undoShape = wasKeyframe ? this . shapes [ frame ] : undefined ;
1292
1300
const redoShape = keyframe ? copyShape ( this . get ( frame ) ) : undefined ;
1293
1301
@@ -2027,7 +2035,7 @@ export class SkeletonShape extends Shape {
2027
2035
protected saveRotation ( rotation , frame ) : void {
2028
2036
const undoSkeletonPoints = this . elements . map ( ( element ) => element . points ) ;
2029
2037
const undoSource = this . source ;
2030
- const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : Source . MANUAL ;
2038
+ const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : computeNewSource ( this . source ) ;
2031
2039
2032
2040
const bbox = computeWrappingBox ( undoSkeletonPoints . flat ( ) ) ;
2033
2041
const [ cx , cy ] = [ bbox . x + bbox . width / 2 , bbox . y + bbox . height / 2 ] ;
@@ -2075,7 +2083,7 @@ export class SkeletonShape extends Shape {
2075
2083
const updateElements = ( affectedElements , action , property : 'points' | 'occluded' | 'hidden' | 'lock' ) => {
2076
2084
const undoSkeletonProperties = this . elements . map ( ( element ) => element [ property ] ) ;
2077
2085
const undoSource = this . source ;
2078
- const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : Source . MANUAL ;
2086
+ const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : computeNewSource ( this . source ) ;
2079
2087
2080
2088
try {
2081
2089
this . history . freeze ( true ) ;
@@ -2246,7 +2254,7 @@ export class MaskShape extends Shape {
2246
2254
const points = mask2Rle ( maskPoints ) ;
2247
2255
2248
2256
const redoPoints = points ;
2249
- const redoSource = Source . MANUAL ;
2257
+ const redoSource = computeNewSource ( this . source ) ;
2250
2258
2251
2259
const undo = ( ) : void => {
2252
2260
this . points = undoPoints ;
@@ -2807,7 +2815,7 @@ export class SkeletonTrack extends Track {
2807
2815
protected saveRotation ( rotation : number , frame : number ) : void {
2808
2816
const undoSkeletonShapes = this . elements . map ( ( element ) => element . shapes [ frame ] ) ;
2809
2817
const undoSource = this . source ;
2810
- const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : Source . MANUAL ;
2818
+ const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : computeNewSource ( this . source ) ;
2811
2819
2812
2820
const elementsData = this . elements . map ( ( element ) => element . get ( frame ) ) ;
2813
2821
const skeletonPoints = elementsData . map ( ( data ) => data . points ) ;
@@ -2952,7 +2960,7 @@ export class SkeletonTrack extends Track {
2952
2960
const undoSkeletonProperties = this . elements . map ( ( element ) => element [ property ] || null ) ;
2953
2961
const undoSkeletonShapes = this . elements . map ( ( element ) => element . shapes [ frame ] ) ;
2954
2962
const undoSource = this . source ;
2955
- const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : Source . MANUAL ;
2963
+ const redoSource = this . readOnlyFields . includes ( 'source' ) ? this . source : computeNewSource ( this . source ) ;
2956
2964
2957
2965
const errors = [ ] ;
2958
2966
try {
0 commit comments