Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix last-select issue when project switched #612

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clean last-selected state when project switched

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
Loading