Skip to content

Commit 93dcce2

Browse files
committed
dragging notes from note tree will automatically insert them as images where appropriate (image, canvas, mermaid)
1 parent 686af0c commit 93dcce2

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/public/app/services/link.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ async function createLink(notePath, options = {}) {
4242
const showNotePath = options.showNotePath === undefined ? false : options.showNotePath;
4343
const showNoteIcon = options.showNoteIcon === undefined ? false : options.showNoteIcon;
4444
const referenceLink = options.referenceLink === undefined ? false : options.referenceLink;
45+
const autoConvertToImage = options.autoConvertToImage === undefined ? false : options.autoConvertToImage;
4546

4647
const { noteId, parentNoteId } = treeService.getNoteIdAndParentIdFromUrl(notePath);
4748
const viewScope = options.viewScope || {};
@@ -58,6 +59,16 @@ async function createLink(notePath, options = {}) {
5859
}
5960
}
6061

62+
const note = await froca.getNote(noteId);
63+
64+
if (autoConvertToImage && ['image', 'canvas', 'mermaid'].includes(note.type) && viewMode === 'default') {
65+
const encodedTitle = encodeURIComponent(linkTitle);
66+
67+
return $("<img>")
68+
.attr("src", `api/images/${noteId}/${encodedTitle}?${Math.random()}`)
69+
.attr("alt", linkTitle);
70+
}
71+
6172
const $container = $("<span>");
6273

6374
if (showNoteIcon) {

src/public/app/widgets/note_tree.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,11 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
402402
}));
403403

404404
if (notes.length === 1) {
405-
linkService.createLink(notes[0].noteId, {referenceLink: true})
405+
linkService.createLink(notes[0].noteId, {referenceLink: true, autoConvertToImage: true})
406406
.then($link => data.dataTransfer.setData("text/html", $link[0].outerHTML));
407407
}
408408
else {
409-
Promise.all(notes.map(note => linkService.createLink(note.noteId, {referenceLink: true}))).then(links => {
409+
Promise.all(notes.map(note => linkService.createLink(note.noteId, {referenceLink: true, autoConvertToImage: true}))).then(links => {
410410
const $list = $("<ul>").append(...links.map($link => $("<li>").append($link)));
411411

412412
data.dataTransfer.setData("text/html", $list[0].outerHTML);

0 commit comments

Comments
 (0)