From c4ab6b48661ac30dad0a479ec97c2ee90df75433 Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 4 Dec 2021 12:45:27 +0100 Subject: [PATCH] copy action in the tree (or ctrl+c) will also save note links to the clipboard, fixes #2401 --- src/public/app/services/clipboard.js | 17 +++++++++++++++-- src/public/app/services/froca.js | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/public/app/services/clipboard.js b/src/public/app/services/clipboard.js index a03782e7b..0e0a9c9e4 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 3cea696db..43cacf48e 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))