fix: don't copy embedded images to its parent note
This commit is contained in:
parent
6bfae7376c
commit
e5e149e6f2
|
|
@ -114,7 +114,7 @@ async function renderSection(
|
|||
if (!targetItem) {
|
||||
continue;
|
||||
}
|
||||
count ++;
|
||||
count++;
|
||||
|
||||
const linkParams = {
|
||||
workspaceUID: (body.closest("bn-workspace") as Workspace)?.dataset.uid,
|
||||
|
|
|
|||
|
|
@ -322,6 +322,10 @@ async function copyEmbeddedImagesFromNote(
|
|||
) {
|
||||
await Zotero.DB.executeTransaction(async () => {
|
||||
for (const fromNote of sourceNotes) {
|
||||
// Do not copy to itself, otherwise the note may break the DB
|
||||
if (!fromNote.id || !targetNote.id || fromNote.id === targetNote.id) {
|
||||
continue;
|
||||
}
|
||||
await Zotero.Notes.copyEmbeddedImages(fromNote, targetNote);
|
||||
}
|
||||
});
|
||||
|
|
@ -361,17 +365,28 @@ async function copyEmbeddedImagesInHTML(
|
|||
doc.querySelectorAll(`img[data-attachment-key="${attachment.key}"]`),
|
||||
) as HTMLImageElement[];
|
||||
if (nodes.length) {
|
||||
let copiedAttachment: Zotero.Item;
|
||||
let copiedAttachment: Zotero.Item | undefined;
|
||||
await Zotero.DB.executeTransaction(async () => {
|
||||
Zotero.DB.requireTransaction();
|
||||
// Do not copy to itself, otherwise the note may break the DB
|
||||
if (
|
||||
!attachment.parentID ||
|
||||
!targetNote.id ||
|
||||
attachment.parentID === targetNote.id
|
||||
) {
|
||||
return;
|
||||
}
|
||||
copiedAttachment = await Zotero.Attachments.copyEmbeddedImage({
|
||||
attachment,
|
||||
note: targetNote,
|
||||
});
|
||||
});
|
||||
if (!copiedAttachment) {
|
||||
continue;
|
||||
}
|
||||
nodes.forEach(
|
||||
(node) =>
|
||||
node?.setAttribute("data-attachment-key", copiedAttachment.key),
|
||||
node?.setAttribute("data-attachment-key", copiedAttachment!.key),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue