Skip to content

Build your personal knowledge base with Trilium Notes

copy action in the tree (or ctrl+c) will also save note links to the clipboard, fixes #2401

zadamc4ab6b48661a
diff --git a/src/public/app/services/clipboard.js b/src/public/app/services/clipboard.js
index a03782e7b9..0e0a9c9e4a 100644
--- a/src/public/app/services/clipboard.js
+++ b/src/public/app/services/clipboard.js
@@ -1,7 +1,8 @@
import branchService from "./branches.js";
import toastService from "./toast.js";
-import hoistedNoteService from "./hoisted_note.js";
import froca from "./froca.js";
+import linkService from "./link.js";
+import utils from "./utils.js";
let clipboardBranchIds = [];
let clipboardMode = null;
@@ -60,10 +61,22 @@ async function pasteInto(parentBranchId) {
}
}
-function copy(branchIds) {
+async function copy(branchIds) {
clipboardBranchIds = branchIds;
clipboardMode = 'copy';
+ if (utils.isElectron()) {
+ const {clipboard} = require('electron');
+ const links = [];
+
+ for (const branch of froca.getBranches(clipboardBranchIds)) {
+ const $link = await linkService.createNoteLink(branch.parentNoteId + '/' + branch.noteId);
+ links.push($link[0].outerHTML);
+ }
+
+ clipboard.writeHTML(links.join(', '));
+ }
+
toastService.showMessage("Note(s) have been copied into clipboard.");
}
diff --git a/src/public/app/services/froca.js b/src/public/app/services/froca.js
index 3cea696db5..43cacf48eb 100644
--- a/src/public/app/services/froca.js
+++ b/src/public/app/services/froca.js
@@ -261,6 +261,7 @@ class Froca {
return (await this.getNotes([noteId], silentNotFoundError))[0];
}
+ /** @returns {Note|null} */
getNoteFromCache(noteId) {
if (!noteId) {
throw new Error("Empty noteId");
@@ -269,6 +270,7 @@ class Froca {
return this.notes[noteId];
}
+ /** @returns {Branch[]} */
getBranches(branchIds, silentNotFoundError = false) {
return branchIds
.map(branchId => this.getBranch(branchId, silentNotFoundError))