From 4da72835fe8246154df44c0435b12b2cadeca672 Mon Sep 17 00:00:00 2001 From: DD <liudi08@gmail.com> Date: Fri, 2 Mar 2018 14:01:51 -0500 Subject: [PATCH] Set index for sounds too. Reseting to sound 0 matches scratch 2 behavior --- src/containers/sound-tab.jsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/containers/sound-tab.jsx b/src/containers/sound-tab.jsx index 471ebe99e..b0b4e3d22 100644 --- a/src/containers/sound-tab.jsx +++ b/src/containers/sound-tab.jsx @@ -46,8 +46,14 @@ class SoundTab extends React.Component { } = nextProps; const target = editingTarget && sprites[editingTarget] ? sprites[editingTarget] : stage; + if (!target || !target.sounds) { + return; + } - if (target && target.sounds && this.state.selectedSoundIndex > target.sounds.length - 1) { + // If switching editing targets, reset the sound index + if (this.props.editingTarget !== editingTarget) { + this.setState({selectedSoundIndex: 0}); + } else if (this.state.selectedSoundIndex > target.sounds.length - 1) { this.setState({selectedSoundIndex: Math.max(target.sounds.length - 1, 0)}); } } -- GitLab