diff --git a/src/public/app/widgets/attachment_detail.js b/src/public/app/widgets/attachment_detail.js index 55c87caaf..4644a02c3 100644 --- a/src/public/app/widgets/attachment_detail.js +++ b/src/public/app/widgets/attachment_detail.js @@ -170,8 +170,20 @@ export default class AttachmentDetailWidget extends BasicWidget { this.$wrapper.find('.attachment-content-wrapper').append((await contentRenderer.getRenderedContent(this.attachment)).$renderedContent); } - copyAttachmentReferenceToClipboard() { - imageService.copyImageReferenceToClipboard(this.$wrapper.find('.attachment-content-wrapper')); + async copyAttachmentLinkToClipboard() { + if (this.attachment.role === 'image') { + imageService.copyImageReferenceToClipboard(this.$wrapper.find('.attachment-content-wrapper')); + } else if (this.attachment.role === 'file') { + const $link = await linkService.createNoteLink(this.attachment.parentId, { + referenceLink: true, + viewScope: { + viewMode: 'attachments', + attachmentId: this.attachment.attachmentId + } + }); + } else { + throw new Error(`Unrecognized attachment role '${this.attachment.role}'.`); + } } async entitiesReloadedEvent({loadResults}) { diff --git a/src/public/app/widgets/buttons/attachments_actions.js b/src/public/app/widgets/buttons/attachments_actions.js index 6a909e0ac..269bdb9cc 100644 --- a/src/public/app/widgets/buttons/attachments_actions.js +++ b/src/public/app/widgets/buttons/attachments_actions.js @@ -33,7 +33,7 @@ const TPL = ` title="File will be open in an external application and watched for changes. You'll then be able to upload the modified version back to Trilium.">Open externally Download Upload new revision - Copy reference to clipboard + Copy link to clipboard Convert attachment into note Delete attachment @@ -56,7 +56,7 @@ export default class AttachmentActionsWidget extends BasicWidget { doRender() { this.$widget = $(TPL); this.$widget.on('click', '.dropdown-item', () => this.$widget.find("[data-toggle='dropdown']").dropdown('toggle')); - this.$widget.find("[data-trigger-command='copyAttachmentReferenceToClipboard']").toggle(this.attachment.role === 'image'); + this.$widget.find("[data-trigger-command='copyAttachmentLinkToClipboard']").toggle(this.attachment.role === 'image'); this.$uploadNewRevisionInput = this.$widget.find(".attachment-upload-new-revision-input"); this.$uploadNewRevisionInput.on('change', async () => { @@ -107,8 +107,8 @@ export default class AttachmentActionsWidget extends BasicWidget { this.$uploadNewRevisionInput.trigger('click'); } - async copyAttachmentReferenceToClipboardCommand() { - this.parent.copyAttachmentReferenceToClipboard(); + async copyAttachmentLinkToClipboardCommand() { + this.parent.copyAttachmentLinkToClipboard(); } async deleteAttachmentCommand() {