mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 08:22:24 -04:00
Move setupMaskEditor() calls
This commit is contained in:
parent
b13a1d1639
commit
0966cd4552
3 changed files with 29 additions and 21 deletions
|
@ -525,21 +525,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({self.note.id}, {self.note.mid});"
|
js = f"loadNote({self.note.id}, {self.note.mid}, {json.dumps(focusTo)}, {json.dumps(self.orig_note_id)});"
|
||||||
|
|
||||||
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 = gui_hooks.editor_will_load_note(js, self.note, self)
|
js = gui_hooks.editor_will_load_note(js, self.note, self)
|
||||||
self.web.evalWithCallback(
|
self.web.evalWithCallback(
|
||||||
f'require("anki/ui").loaded.then(() => {{ {js} }})', oncallback
|
f'require("anki/ui").loaded.then(() => {{ {js} }})', oncallback
|
||||||
|
|
|
@ -511,7 +511,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
function setImageField(html) {
|
function setImageField(html) {
|
||||||
fieldStores[ioFields.image].set(html);
|
fieldStores[ioFields.image].set(html);
|
||||||
}
|
}
|
||||||
globalThis.setImageField = setImageField;
|
|
||||||
|
|
||||||
function saveOcclusions(): void {
|
function saveOcclusions(): void {
|
||||||
if (isImageOcclusion && globalThis.canvas) {
|
if (isImageOcclusion && globalThis.canvas) {
|
||||||
|
@ -535,7 +534,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
page.remove();
|
page.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
globalThis.resetIOImageLoaded = resetIOImageLoaded;
|
|
||||||
|
|
||||||
/** hide occlusions and image */
|
/** hide occlusions and image */
|
||||||
function hideFieldInOcclusionType(
|
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({
|
const notetype = await getNotetype({
|
||||||
ntid: notetypeId,
|
ntid: notetypeId,
|
||||||
});
|
});
|
||||||
|
@ -649,6 +647,28 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
if (mode === "add") {
|
if (mode === "add") {
|
||||||
setSticky(notetype.fields.map((field) => field.config?.sticky ?? false));
|
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();
|
triggerChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -701,6 +721,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
triggerChanges,
|
triggerChanges,
|
||||||
setIsImageOcclusion,
|
setIsImageOcclusion,
|
||||||
setupMaskEditor,
|
setupMaskEditor,
|
||||||
|
setImageField,
|
||||||
|
resetIOImageLoaded,
|
||||||
saveOcclusions,
|
saveOcclusions,
|
||||||
setSticky,
|
setSticky,
|
||||||
...oldEditorAdapter,
|
...oldEditorAdapter,
|
||||||
|
|
|
@ -3,18 +3,18 @@
|
||||||
|
|
||||||
export interface IOAddingMode {
|
export interface IOAddingMode {
|
||||||
kind: "add";
|
kind: "add";
|
||||||
notetypeId: number;
|
notetypeId: bigint;
|
||||||
imagePath: string;
|
imagePath: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IOCloningMode {
|
export interface IOCloningMode {
|
||||||
kind: "add";
|
kind: "add";
|
||||||
clonedNoteId: number;
|
clonedNoteId: bigint;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IOEditingMode {
|
export interface IOEditingMode {
|
||||||
kind: "edit";
|
kind: "edit";
|
||||||
noteId: number;
|
noteId: bigint;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type IOMode = IOAddingMode | IOEditingMode | IOCloningMode;
|
export type IOMode = IOAddingMode | IOEditingMode | IOCloningMode;
|
||||||
|
|
Loading…
Reference in a new issue