diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index 582271b62..ea18263c4 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -387,20 +387,24 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too if type == "blur": self.currentField = None # run any filters - if gui_hooks.editor_did_unfocus_field(False, self.note, ord): + if self.note and gui_hooks.editor_did_unfocus_field( + False, self.note, ord + ): # something updated the note; update it after a subsequent focus # event has had time to fire self.mw.progress.timer( 100, self.loadNoteKeepingFocus, False, parent=self.widget ) else: - gui_hooks.editor_did_fire_typing_timer(self.note) + if self.note: + gui_hooks.editor_did_fire_typing_timer(self.note) # focused into field? elif cmd.startswith("focus"): (type, num) = cmd.split(":", 1) self.last_field_index = self.currentField = int(num) - gui_hooks.editor_did_focus_field(self.note, self.currentField) + if self.note: + gui_hooks.editor_did_focus_field(self.note, self.currentField) elif cmd.startswith("toggleStickyAll"): model = self.note_type() @@ -436,7 +440,8 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too return new_state elif cmd.startswith("saveTags"): - gui_hooks.editor_did_update_tags(self.note) + if self.note: + gui_hooks.editor_did_update_tags(self.note) elif cmd.startswith("editorState"): (_, new_state_id, old_state_id) = cmd.split(":", 2) @@ -516,13 +521,15 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too assert self.mw.pm.profile is not None js = f"loadNote({json.dumps(self.nid)}, {mid}, {json.dumps(focus_to)}, {json.dumps(self.orig_note_id)});" - js = gui_hooks.editor_will_load_note(js, self.note, self) + if self.note: + js = gui_hooks.editor_will_load_note(js, self.note, self) self.web.evalWithCallback( f'require("anki/ui").loaded.then(() => {{ {js} }})', oncallback ) @deprecated(replaced_by=load_note) def loadNote(self, focusTo: int | None = None) -> None: + assert self.note is not None self.load_note(self.note.mid, focus_to=focusTo) def call_after_note_saved( diff --git a/ts/routes/editor/NoteEditor.svelte b/ts/routes/editor/NoteEditor.svelte index d7b2e214f..104258d2a 100644 --- a/ts/routes/editor/NoteEditor.svelte +++ b/ts/routes/editor/NoteEditor.svelte @@ -372,28 +372,28 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html async function noteCanBeAdded(): Promise { let problem: string | null = null; const result = await noteFieldsCheck(note!); - if(result.state === NoteFieldsCheckResponse_State.EMPTY) { - if(isImageOcclusion) { + if (result.state === NoteFieldsCheckResponse_State.EMPTY) { + if (isImageOcclusion) { problem = tr.notetypesNoOcclusionCreated2(); } else { problem = tr.addingTheFirstFieldIsEmpty(); } } - if(result.state === NoteFieldsCheckResponse_State.MISSING_CLOZE) { + if (result.state === NoteFieldsCheckResponse_State.MISSING_CLOZE) { // TODO: askUser(tr.addingYouHaveAClozeDeletionNote()) return false; } - if(result.state === NoteFieldsCheckResponse_State.NOTETYPE_NOT_CLOZE) { + if (result.state === NoteFieldsCheckResponse_State.NOTETYPE_NOT_CLOZE) { problem = tr.addingClozeOutsideClozeNotetype(); } - if(result.state === NoteFieldsCheckResponse_State.FIELD_NOT_CLOZE) { + if (result.state === NoteFieldsCheckResponse_State.FIELD_NOT_CLOZE) { problem = tr.addingClozeOutsideClozeField(); } return problem ? false : true; } async function addCurrentNoteInner(deckId: bigint) { - if(!await noteCanBeAdded()) { + if (!(await noteCanBeAdded())) { return; } await addNote({ @@ -404,10 +404,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html } export async function addCurrentNote(deckId: bigint) { - if(mode !== "add") { + if (mode !== "add") { return; } - if(isImageOcclusion) { + if (isImageOcclusion) { saveOcclusions(); await addCurrentNoteInner(deckId); resetIOImageLoaded(); @@ -679,7 +679,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html } else { setNote( await getNote({ - nid!, + nid: nid!, }), ); } diff --git a/ts/routes/image-occlusion/[...imagePathOrNoteId]/+page.ts b/ts/routes/image-occlusion/[...imagePathOrNoteId]/+page.ts index 6f83cc44c..beb0fde55 100644 --- a/ts/routes/image-occlusion/[...imagePathOrNoteId]/+page.ts +++ b/ts/routes/image-occlusion/[...imagePathOrNoteId]/+page.ts @@ -15,9 +15,9 @@ async function save(): Promise { export const load = (async ({ params }) => { let mode: IOMode; if (/^\d+/.test(params.imagePathOrNoteId)) { - mode = { kind: "edit", noteId: Number(params.imagePathOrNoteId) }; + mode = { kind: "edit", noteId: BigInt(params.imagePathOrNoteId) }; } else { - mode = { kind: "add", imagePath: params.imagePathOrNoteId, notetypeId: 0 }; + mode = { kind: "add", imagePath: params.imagePathOrNoteId, notetypeId: 0n }; } // for adding note from mobile devices diff --git a/ts/routes/image-occlusion/add-or-update-note.svelte.ts b/ts/routes/image-occlusion/add-or-update-note.svelte.ts index ce31eaaaf..98955f7a5 100644 --- a/ts/routes/image-occlusion/add-or-update-note.svelte.ts +++ b/ts/routes/image-occlusion/add-or-update-note.svelte.ts @@ -31,7 +31,7 @@ export const addOrUpdateNote = async function( if (mode.kind == "edit") { const result = await updateImageOcclusionNote({ - noteId: BigInt(mode.noteId), + noteId: mode.noteId, occlusions: occlusionCloze, header, backExtra, @@ -53,7 +53,7 @@ export const addOrUpdateNote = async function( }; // show toast message -const showResult = (noteId: number | null, result: OpChanges, count: number) => { +const showResult = (noteId: bigint | null, result: OpChanges, count: number) => { const props = $state({ message: "", type: "error" as "error" | "success", diff --git a/ts/routes/image-occlusion/index.ts b/ts/routes/image-occlusion/index.ts index 59720b1e0..84bf8cd87 100644 --- a/ts/routes/image-occlusion/index.ts +++ b/ts/routes/image-occlusion/index.ts @@ -50,10 +50,10 @@ export async function setupImageOcclusion(mode: IOMode, target = document.body): if (window.location.hash.startsWith("#test-")) { const imagePath = window.location.hash.replace("#test-", ""); - setupImageOcclusion({ kind: "add", imagePath, notetypeId: 0 }); + setupImageOcclusion({ kind: "add", imagePath, notetypeId: 0n }); } if (window.location.hash.startsWith("#testforedit-")) { - const noteId = parseInt(window.location.hash.replace("#testforedit-", "")); + const noteId = BigInt(window.location.hash.replace("#testforedit-", "")); setupImageOcclusion({ kind: "edit", noteId }); } diff --git a/ts/routes/image-occlusion/mask-editor.ts b/ts/routes/image-occlusion/mask-editor.ts index c5492d413..4602f5b19 100644 --- a/ts/routes/image-occlusion/mask-editor.ts +++ b/ts/routes/image-occlusion/mask-editor.ts @@ -44,7 +44,7 @@ export const setupMaskEditor = async ( }; export const setupMaskEditorForEdit = async ( - noteId: number, + noteId: bigint, onImageLoaded: (event: ImageLoadedEvent) => void, ): Promise => { const clozeNoteResponse = await getImageOcclusionNote({ noteId: BigInt(noteId) });