Skip to content

Commit caf48a0

Browse files
committed
fixed bug with empty array, and animated control instr
1 parent 62a3fdc commit caf48a0

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/features/cseMachine/CseMachineAnimation.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ export class CseAnimation {
113113
);
114114
}
115115
break;
116+
case 'SpreadElement':
117+
CseAnimation.animations.push(
118+
new ControlExpansionAnimation(lastControlComponent, CseAnimation.getNewControlItems()),
119+
);
120+
break;
116121
case 'AssignmentExpression':
117122
case 'ArrayExpression':
118123
case 'BinaryExpression':
@@ -281,6 +286,9 @@ export class CseAnimation {
281286
const prevcontrol = Layout.previousControlComponent.stackItemComponents;
282287
const control = Layout.controlComponent.stackItemComponents;
283288
const array = Layout.previousStashComponent.stashItemComponents.at(-1)!.arrow!.target! as ArrayValue;
289+
290+
console.log(array);
291+
284292
let currCallInstr;
285293
let prevCallInstr;
286294

@@ -299,12 +307,14 @@ export class CseAnimation {
299307
break;
300308
}
301309
}
310+
311+
const resultItems = array.data.length !== 0 ? Layout.stashComponent.stashItemComponents.slice(-array.data.length) : [];
302312

303313
CseAnimation.animations.push(
304314
new ArraySpreadAnimation(
305315
lastControlComponent,
306316
Layout.previousStashComponent.stashItemComponents.at(-1)!,
307-
Layout.stashComponent.stashItemComponents.slice(-array.data.length)!,
317+
resultItems!,
308318
currCallInstr!,
309319
prevCallInstr!
310320
)

src/features/cseMachine/animationComponents/ArraySpreadAnimation.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export class ArraySpreadAnimation extends Animatable {
2929
private prevCallInstrAnimation: AnimatedTextbox;
3030

3131
private endX: number;
32-
private resultItemIsFirst: boolean;
3332

3433
constructor(
3534
private controlInstrItem: ControlItemComponent,
@@ -39,7 +38,10 @@ export class ArraySpreadAnimation extends Animatable {
3938
private prevCallInstrItem: ControlItemComponent
4039
) {
4140
super();
42-
this.resultItemIsFirst = (resultItems[0]?.index ?? stashItem.index) === 0;
41+
42+
console.log(stashItem);
43+
console.log(resultItems);
44+
4345
this.endX = stashItem!.x() + stashItem!.width();
4446
this.controlInstrAnimation = new AnimatedTextbox(
4547
controlInstrItem.text,
@@ -97,7 +99,7 @@ export class ArraySpreadAnimation extends Animatable {
9799
getTextWidth(this.controlInstrItem.text) + ControlStashConfig.ControlItemTextPadding * 2;
98100
const resultX = (idx: number) => this.resultItems[idx]?.x() ?? this.stashItem.x();
99101
const resultY = this.resultItems[0]?.y() ?? this.stashItem.y();
100-
const startX = resultX(0) - (this.resultItemIsFirst ? minInstrWidth : 0);
102+
const startX = resultX(0);
101103
const fadeDuration = ((animationConfig?.duration ?? 1) * 3) / 4;
102104
const fadeInDelay = (animationConfig?.delay ?? 0) + (animationConfig?.duration ?? 1) / 4;
103105

@@ -121,7 +123,7 @@ export class ArraySpreadAnimation extends Animatable {
121123
...this.resultAnimations.flatMap(a => [
122124

123125
a.animateTo(
124-
{ x: startX + (this.endX - startX) / 2 - this.resultItems[0]!.width() / 2 },
126+
{ x: startX + (this.endX - startX) / 2 - this.resultItems[0]?.width() / 2 },
125127
{ duration: 0 }
126128
)
127129
]),
@@ -131,9 +133,7 @@ export class ArraySpreadAnimation extends Animatable {
131133
x: startX,
132134
y:
133135
resultY +
134-
(this.resultItemIsFirst
135-
? 0
136-
: (this.resultItems[0].height() ?? this.stashItem.height())),
136+
(this.resultItems[0]?.height() ?? this.stashItem.height()),
137137
width: minInstrWidth
138138
},
139139
animationConfig

0 commit comments

Comments
 (0)