Skip to content

Commit

Permalink
fix last-select issue when project switched
Browse files Browse the repository at this point in the history
  • Loading branch information
nighca committed Jun 25, 2024
1 parent 9203581 commit 00e969b
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions spx-gui/src/components/editor/panels/EditorPanels.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</template>

<script setup lang="ts">
import { ref, watch, shallowRef } from 'vue'
import { ref, watch, shallowRef, effectScope } from 'vue'
import { UICard } from '@/components/ui'
import { useEditorCtx } from '@/components/editor/EditorContextProvider.vue'
import SoundsPanel from './sound/SoundsPanel.vue'
Expand All @@ -36,12 +36,24 @@ watch(
const lastSelectedSprite = shallowRef<string | null>(null)
const lastSelectedSound = shallowRef<string | null>(null)
const watchScope = effectScope()
watch(
() => editorCtx.project.selected,
(_, lastSelected) => {
if (lastSelected?.type === 'sprite') lastSelectedSprite.value = lastSelected.name
else if (lastSelected?.type === 'sound') lastSelectedSound.value = lastSelected.name
}
() => editorCtx.project,
(project, _, onCleanup) => {
lastSelectedSprite.value = null
lastSelectedSound.value = null
// use standalone effect scope to avoid error when clean up, see details in https://github.com/vuejs/core/issues/5783
watchScope.run(() => {
onCleanup(watch(
() => project.selected,
(_, lastSelected) => {
if (lastSelected?.type === 'sprite') lastSelectedSprite.value = lastSelected.name
else if (lastSelected?.type === 'sound') lastSelectedSound.value = lastSelected.name
}
))
})
},
{ immediate: true }
)
watch(
Expand Down

0 comments on commit 00e969b

Please sign in to comment.