diff --git a/src/elements/linkCreator/inboundCreator.ts b/src/elements/linkCreator/inboundCreator.ts index 4b470d0..3135ede 100644 --- a/src/elements/linkCreator/inboundCreator.ts +++ b/src/elements/linkCreator/inboundCreator.ts @@ -66,11 +66,10 @@ export class InboundCreator extends PluginCEBase { async accept(io: any) { if (!this.targetNote) return; - const content = await this.getContentToInsert(); this.notePicker.saveRecentNotes(); io.targetNoteID = this.targetNote.id; - io.content = content; + io.sourceNoteIDs = [this.currentNote!.id]; io.lineIndex = this.getIndexToInsert(); } @@ -216,21 +215,11 @@ export class InboundCreator extends PluginCEBase { async getContentToInsert() { if (!this.currentNote || !this.targetNote) return ""; - const forwardLink = this._addon.api.convert.note2link(this.currentNote, {}); - const content = await this._addon.api.template.runTemplate( - "[QuickInsertV2]", - "link, linkText, subNoteItem, noteItem", - [ - forwardLink, - this.currentNote.getNoteTitle().trim() || forwardLink, - this.currentNote, - this.targetNote, - ], - { - dryRun: true, - }, + return await this._addon.api.template.runQuickInsertTemplate( + this.currentNote, + this.targetNote, + { dryRun: true }, ); - return content; } getIndexToInsert() { diff --git a/src/elements/linkCreator/outboundCreator.ts b/src/elements/linkCreator/outboundCreator.ts index 86f4004..13e037e 100644 --- a/src/elements/linkCreator/outboundCreator.ts +++ b/src/elements/linkCreator/outboundCreator.ts @@ -69,10 +69,10 @@ export class OutboundCreator extends PluginCEBase { async accept(io: any) { if (!this.targetNotes) return; - const content = await this.getContentToInsert(); this.notePicker.saveRecentNotes(); io.targetNoteID = this.currentNote!.id; + io.sourceNoteIDs = this.targetNotes.map((item) => item.id).filter(Boolean); io.content = content; io.lineIndex = this.getIndexToInsert(); } @@ -240,19 +240,10 @@ export class OutboundCreator extends PluginCEBase { if (!this.currentNote || !this.targetNotes?.length) return ""; let content = ""; for (const note of this.targetNotes) { - const forwardLink = this._addon.api.convert.note2link(note, {}); - content += await this._addon.api.template.runTemplate( - "[QuickInsertV2]", - "link, linkText, subNoteItem, noteItem", - [ - forwardLink, - note.getNoteTitle().trim() || forwardLink, - note, - this.currentNote, - ], - { - dryRun: true, - }, + content += await this._addon.api.template.runQuickInsertTemplate( + note, + this.currentNote, + { dryRun: true }, ); content += "\n"; } diff --git a/src/utils/linkCreator.ts b/src/utils/linkCreator.ts index 268337a..475e70c 100644 --- a/src/utils/linkCreator.ts +++ b/src/utils/linkCreator.ts @@ -41,10 +41,20 @@ async function openLinkCreator( await io.deferred.promise; const targetNote = Zotero.Items.get(io.targetNoteID); - const content = io.content; - const lineIndex = io.lineIndex; - if (!targetNote || !content) return; + if (!targetNote) return; + + const sourceNotes = Zotero.Items.get(io.sourceNoteIDs as number[]); + let content = ""; + for (const note of sourceNotes) { + content += await addon.api.template.runQuickInsertTemplate( + note, + targetNote, + { dryRun: false }, + ); + content += "\n"; + } + const lineIndex = io.lineIndex; await addLineToNote(targetNote, content, lineIndex); }