diff --git a/ts/deck-options/lib.test.ts b/ts/deck-options/lib.test.ts index c54fedcb1..4daec7946 100644 --- a/ts/deck-options/lib.test.ts +++ b/ts/deck-options/lib.test.ts @@ -109,13 +109,13 @@ test("deck list", () => { expect(get(state.configList)).toStrictEqual([ { current: true, - idx: 1, + idx: 0, name: "another one", useCount: 1, }, { current: false, - idx: 0, + idx: 1, name: "Default", useCount: 1, }, @@ -150,13 +150,13 @@ test("deck list", () => { }, { current: true, - idx: 2, + idx: 1, name: "hello", useCount: 1, }, { current: false, - idx: 1, + idx: 2, name: "zzz", useCount: 0, }, @@ -174,13 +174,13 @@ test("deck list", () => { }, { current: false, - idx: 2, + idx: 1, name: "hello", useCount: 0, }, { current: false, - idx: 1, + idx: 2, name: "zzz", useCount: 0, }, @@ -230,7 +230,7 @@ test("parent counts", () => { expect(get(state.parentLimits)).toStrictEqual({ newCards: 10, reviews: 200 }); // but adjusting the default config will, since the parent deck uses it - state.setCurrentIndex(0); + state.setCurrentIndex(1); state.currentConfig.update((c) => { c.newPerDay = 123; return c; @@ -269,7 +269,7 @@ test("saving", () => { expect(out.removedConfigIds).toStrictEqual([]); // select the other non-default deck & remove - state.setCurrentIndex(1); + state.setCurrentIndex(0); state.removeCurrentConfig(); // should be listed in removedConfigs, and modified should @@ -287,7 +287,7 @@ test("aux data", () => { }); // check default - state.setCurrentIndex(0); + state.setCurrentIndex(1); expect(get(state.currentAuxData)).toStrictEqual({ new: { separate: true, diff --git a/ts/deck-options/lib.ts b/ts/deck-options/lib.ts index 6f8a4a65a..5a5428a4a 100644 --- a/ts/deck-options/lib.ts +++ b/ts/deck-options/lib.ts @@ -65,6 +65,7 @@ export class DeckOptionsState { 0, this.configs.findIndex((c) => c.config.id === this.currentDeck.configId), ); + this.sortConfigs(); this.v3Scheduler = data.v3Scheduler; this.cardStateCustomizer = writable(data.cardStateCustomizer); this.deckLimits = writable(data.currentDeck?.limits ?? createLimits()); @@ -116,6 +117,7 @@ export class DeckOptionsState { if (config.id) { this.modifiedConfigs.add(config.id); } + this.sortConfigs(); this.updateConfigList(); } @@ -140,6 +142,7 @@ export class DeckOptionsState { const configWithCount = { config, useCount: 0 }; this.configs.push(configWithCount); this.selectedIdx = this.configs.length - 1; + this.sortConfigs(); this.updateCurrentConfig(); this.updateConfigList(); } @@ -254,6 +257,16 @@ export class DeckOptionsState { return bytesToObject(conf.other); } + private sortConfigs() { + const currentConfigName = this.configs[this.selectedIdx].config.name; + this.configs.sort((a, b) => + localeCompare(a.config.name, b.config.name, { sensitivity: "base" }), + ); + this.selectedIdx = this.configs.findIndex( + (c) => c.config.name == currentConfigName, + ); + } + private getConfigList(): ConfigListEntry[] { const list: ConfigListEntry[] = this.configs.map((c, idx) => { const useCount = c.useCount + (idx === this.selectedIdx ? 1 : 0); @@ -264,7 +277,6 @@ export class DeckOptionsState { useCount, }; }); - list.sort((a, b) => localeCompare(a.name, b.name, { sensitivity: "base" })); return list; }