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

This commit is contained in:
zadam 2021-12-04 12:45:27 +01:00
parent 630d9f2e45
commit c4ab6b4866
2 changed files with 17 additions and 2 deletions

View file

@ -1,7 +1,8 @@
import branchService from "./branches.js"; import branchService from "./branches.js";
import toastService from "./toast.js"; import toastService from "./toast.js";
import hoistedNoteService from "./hoisted_note.js";
import froca from "./froca.js"; import froca from "./froca.js";
import linkService from "./link.js";
import utils from "./utils.js";
let clipboardBranchIds = []; let clipboardBranchIds = [];
let clipboardMode = null; let clipboardMode = null;
@ -60,10 +61,22 @@ async function pasteInto(parentBranchId) {
} }
} }
function copy(branchIds) { async function copy(branchIds) {
clipboardBranchIds = branchIds; clipboardBranchIds = branchIds;
clipboardMode = 'copy'; 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."); toastService.showMessage("Note(s) have been copied into clipboard.");
} }

View file

@ -261,6 +261,7 @@ class Froca {
return (await this.getNotes([noteId], silentNotFoundError))[0]; return (await this.getNotes([noteId], silentNotFoundError))[0];
} }
/** @returns {Note|null} */
getNoteFromCache(noteId) { getNoteFromCache(noteId) {
if (!noteId) { if (!noteId) {
throw new Error("Empty noteId"); throw new Error("Empty noteId");
@ -269,6 +270,7 @@ class Froca {
return this.notes[noteId]; return this.notes[noteId];
} }
/** @returns {Branch[]} */
getBranches(branchIds, silentNotFoundError = false) { getBranches(branchIds, silentNotFoundError = false) {
return branchIds return branchIds
.map(branchId => this.getBranch(branchId, silentNotFoundError)) .map(branchId => this.getBranch(branchId, silentNotFoundError))