diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index ac5a68a34..8653ec384 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -525,21 +525,7 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too gui_hooks.editor_did_load_note(self) assert self.mw.pm.profile is not None - js = f"loadNote({self.note.id}, {self.note.mid});" - - if self.current_notetype_is_image_occlusion(): - io_field_indices = self.mw.backend.get_image_occlusion_fields(self.note.mid) - image_field = self.note.fields[io_field_indices.image] - self.last_io_image_path = self.extract_img_path_from_html(image_field) - - if self.editorMode is not EditorMode.ADD_CARDS: - io_options = self._create_edit_io_options(note_id=self.note.id) - js += " setupMaskEditor(%s);" % json.dumps(io_options) - elif orig_note_id := self.orig_note_id: - self.orig_note_id = None - io_options = self._create_clone_io_options(orig_note_id) - js += " setupMaskEditor(%s);" % json.dumps(io_options) - + js = f"loadNote({self.note.id}, {self.note.mid}, {json.dumps(focusTo)}, {json.dumps(self.orig_note_id)});" js = gui_hooks.editor_will_load_note(js, self.note, self) self.web.evalWithCallback( f'require("anki/ui").loaded.then(() => {{ {js} }})', oncallback diff --git a/ts/routes/editor/NoteEditor.svelte b/ts/routes/editor/NoteEditor.svelte index 9385cc277..e287dadf7 100644 --- a/ts/routes/editor/NoteEditor.svelte +++ b/ts/routes/editor/NoteEditor.svelte @@ -511,7 +511,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html function setImageField(html) { fieldStores[ioFields.image].set(html); } - globalThis.setImageField = setImageField; function saveOcclusions(): void { if (isImageOcclusion && globalThis.canvas) { @@ -535,7 +534,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html page.remove(); } } - globalThis.resetIOImageLoaded = resetIOImageLoaded; /** hide occlusions and image */ function hideFieldInOcclusionType( @@ -587,7 +585,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html }); } - async function loadNote(nid: bigint, notetypeId: bigint, focusTo: number) { + async function loadNote(nid: bigint, notetypeId: bigint, focusTo: number, originalNoteId: bigint | null) { const notetype = await getNotetype({ ntid: notetypeId, }); @@ -649,6 +647,28 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html if (mode === "add") { setSticky(notetype.fields.map((field) => field.config?.sticky ?? false)); } + if(isImageOcclusion) { + const imageField = note!.fields[ioFields.image]; + // TODO: last_io_image_path + if(mode !== "add") { + setupMaskEditor({ + html: imageField, + mode: { + kind: "edit", + noteId: nid, + }, + }); + } + else if(originalNoteId) { + setupMaskEditor({ + html: imageField, + mode: { + kind: "add", + clonedNoteId: originalNoteId, + }, + }); + } + } triggerChanges(); } @@ -701,6 +721,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html triggerChanges, setIsImageOcclusion, setupMaskEditor, + setImageField, + resetIOImageLoaded, saveOcclusions, setSticky, ...oldEditorAdapter, diff --git a/ts/routes/image-occlusion/lib.ts b/ts/routes/image-occlusion/lib.ts index 8986fa3ff..d8b9e7294 100644 --- a/ts/routes/image-occlusion/lib.ts +++ b/ts/routes/image-occlusion/lib.ts @@ -3,18 +3,18 @@ export interface IOAddingMode { kind: "add"; - notetypeId: number; + notetypeId: bigint; imagePath: string; } export interface IOCloningMode { kind: "add"; - clonedNoteId: number; + clonedNoteId: bigint; } export interface IOEditingMode { kind: "edit"; - noteId: number; + noteId: bigint; } export type IOMode = IOAddingMode | IOEditingMode | IOCloningMode;