Fix selected notetype/deck reverting back to defaults

This commit is contained in:
Abdo 2025-08-27 02:01:10 +03:00
parent c1a44ce867
commit ba881d4e90
2 changed files with 14 additions and 9 deletions

View file

@ -427,7 +427,7 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
gui_hooks.editor_did_load_note(self) gui_hooks.editor_did_load_note(self)
assert self.mw.pm.profile is not None assert self.mw.pm.profile is not None
js = f"loadNote({json.dumps(self.nid)}, {mid}, {json.dumps(focus_to)}, {json.dumps(original_note_id)}, {json.dumps(self.mw.reviewer.card.id if self.mw.reviewer.card else None)});" js = f"loadNote({json.dumps(self.nid)}, {mid}, {json.dumps(focus_to)}, {json.dumps(original_note_id)}, {json.dumps(self.mw.reviewer.card.id if self.mw.reviewer.card else None)}, true);"
self.web.evalWithCallback( self.web.evalWithCallback(
f'require("anki/ui").loaded.then(() => {{ {js} }})', oncallback f'require("anki/ui").loaded.then(() => {{ {js} }})', oncallback
) )

View file

@ -305,7 +305,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
export let selectedDeck: DeckNameId | null = null; export let selectedDeck: DeckNameId | null = null;
async function onNotetypeChange(notetype: NotetypeNameId) { async function onNotetypeChange(notetype: NotetypeNameId) {
loadNote(0n, notetype.id, 0, null, null); loadNote(0n, notetype.id, 0, null, reviewerCard?.id ?? null);
if ( if (
!(await getConfigBool({ !(await getConfigBool({
key: ConfigKey_Bool.ADDING_DEFAULTS_TO_CURRENT_DECK, key: ConfigKey_Bool.ADDING_DEFAULTS_TO_CURRENT_DECK,
@ -519,7 +519,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
} }
async function loadNewNote() { async function loadNewNote() {
await loadNote(0n, notetypeMeta.id, 0, null, null); await loadNote(0n, notetypeMeta.id, 0, null, reviewerCard?.id ?? null);
} }
async function noteCanBeAdded(): Promise<boolean> { async function noteCanBeAdded(): Promise<boolean> {
@ -953,6 +953,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
focusTo: number, focusTo: number,
originalNoteId: bigint | null, originalNoteId: bigint | null,
reviewerCardId: bigint | null, reviewerCardId: bigint | null,
initial: boolean = false,
) { ) {
const notetype = await getNotetype({ const notetype = await getNotetype({
ntid: notetypeId, ntid: notetypeId,
@ -987,11 +988,13 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
reviewerCard = await getCard({ cid: reviewerCardId }); reviewerCard = await getCard({ cid: reviewerCardId });
homeDeckId = reviewerCard.originalDeckId || reviewerCard.deckId; homeDeckId = reviewerCard.originalDeckId || reviewerCard.deckId;
} }
const chooserDefaults = await defaultsForAdding({ if (initial) {
homeDeckOfCurrentReviewCard: homeDeckId, const chooserDefaults = await defaultsForAdding({
}); homeDeckOfCurrentReviewCard: homeDeckId,
notetypeChooser.select(chooserDefaults.notetypeId); });
deckChooser.select(chooserDefaults.deckId); notetypeChooser.select(chooserDefaults.notetypeId);
deckChooser.select(chooserDefaults.deckId);
}
const fieldValues = ( const fieldValues = (
await Promise.all( await Promise.all(
@ -1073,6 +1076,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
focusTo: number, focusTo: number,
originalNoteId: bigint | null, originalNoteId: bigint | null,
reviewerCardId: bigint | null, reviewerCardId: bigint | null,
initial: boolean = false,
) { ) {
loadDebouncer.schedule(async () => { loadDebouncer.schedule(async () => {
await loadNoteInner( await loadNoteInner(
@ -1081,12 +1085,13 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
focusTo, focusTo,
originalNoteId, originalNoteId,
reviewerCardId, reviewerCardId,
initial,
); );
}); });
} }
async function reloadNote() { async function reloadNote() {
await loadNote(note!.id, notetypeMeta.id, 0, null); await loadNote(note!.id, notetypeMeta.id, 0, null, reviewerCard?.id ?? null);
} }
function checkNonLegacy(value: any): any | undefined { function checkNonLegacy(value: any): any | undefined {