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 auto selection after sound removed #776

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
fix auto selection
  • Loading branch information
nighca committed Aug 20, 2024
commit 6d5d5302c1d787edebb6674d62dba667217f5023
51 changes: 51 additions & 0 deletions spx-gui/src/models/project/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,55 @@ describe('Project', () => {
expect(project.sprites.map((s) => s.name)).toEqual(['Sprite1', 'Sprite3', 'Sprite2'])
expect(project.sounds.map((s) => s.name)).toEqual(['sound1', 'sound3', 'sound2'])
})

it('should select correctly after sound removed', async () => {
const project = makeProject()
const sprite2 = new Sprite('Sprite2')
project.addSprite(sprite2)
const sound2 = new Sound('sound2', mockFile())
project.addSound(sound2)
const sound3 = new Sound('sound3', mockFile())
project.addSound(sound3)

project.select({ type: 'stage' })
project.removeSound('sound3')
expect(project.selected).toEqual({ type: 'stage' })

project.select({ type: 'sound', name: 'sound' })

project.removeSound('sound')
expect(project.selected).toEqual({
type: 'sound',
name: 'sound2'
})

project.removeSound('sound2')
expect(project.selected).toEqual({
type: 'sprite',
name: 'Sprite'
})
})

it('should select correctly after sprite removed', async () => {
const project = makeProject()
const sprite2 = new Sprite('Sprite2')
project.addSprite(sprite2)
const sprite3 = new Sprite('Sprite3')
project.addSprite(sprite3)

project.select({ type: 'stage' })
project.removeSprite('Sprite3')
expect(project.selected).toEqual({ type: 'stage' })

project.select({ type: 'sprite', name: 'Sprite' })

project.removeSprite('Sprite')
expect(project.selected).toEqual({
type: 'sprite',
name: 'Sprite2'
})

project.removeSprite('Sprite2')
expect(project.selected).toBeNull()
})
})
11 changes: 6 additions & 5 deletions spx-gui/src/models/project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,12 @@ export class Project extends Disposable {
*/
private autoSelect() {
const selected = this.selected
if (selected?.type === 'sprite' && this.selectedSprite == null) {
this.select(this.sprites[0] != null ? { type: 'sprite', name: this.sprites[0].name } : null)
} else if (selected?.type === 'sound' && this.selectedSound == null) {
this.select(this.sounds[0] != null ? { type: 'sound', name: this.sounds[0].name } : null)
} else if (selected == null) {
if (selected?.type === 'stage') return
if (selected?.type === 'sound' && this.selectedSound == null && this.sounds[0] != null) {
this.select({ type: 'sound', name: this.sounds[0].name })
return
}
if (this.selectedSprite == null) {
this.select(this.sprites[0] != null ? { type: 'sprite', name: this.sprites[0].name } : null)
}
}
Expand Down
Loading