From 6ea77b36ce8e2caf320678fea48f94457ed1b779 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sun, 30 Sep 2018 20:15:30 +0100 Subject: [PATCH] Electron: Resolves #820: Allow dragging and dropping a note in another note to create a link --- ElectronClient/app/gui/NoteText.jsx | 18 +++++++++++++++++- ReactNativeClient/lib/models/BaseItem.js | 7 ++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/ElectronClient/app/gui/NoteText.jsx b/ElectronClient/app/gui/NoteText.jsx index 207e4ca1d..0cfc89e24 100644 --- a/ElectronClient/app/gui/NoteText.jsx +++ b/ElectronClient/app/gui/NoteText.jsx @@ -142,7 +142,20 @@ class NoteTextComponent extends React.Component { } this.onDrop_ = async (event) => { - const files = event.dataTransfer.files; + const dt = event.dataTransfer; + + if (dt.types.indexOf("text/x-jop-note-ids") >= 0) { + const noteIds = JSON.parse(dt.getData("text/x-jop-note-ids")); + const linkText = []; + for (let i = 0; i < noteIds.length; i++) { + const note = await Note.load(noteIds[i]); + linkText.push(Note.markdownTag(note)); + } + + this.wrapSelectionWithStrings("", "", '', linkText.join('\n')); + } + + const files = dt.files; if (!files || !files.length) return; const filesToAttach = []; @@ -1025,6 +1038,9 @@ class NoteTextComponent extends React.Component { end: { row: p.row, column: p.column + middleText.length }, }; + // BUG!! If replacementText contains newline characters, the logic + // to select the new text will not work. + this.updateEditorWithDelay((editor) => { if (middleText && newRange) { const range = this.selectionRange_; diff --git a/ReactNativeClient/lib/models/BaseItem.js b/ReactNativeClient/lib/models/BaseItem.js index d0c2843f7..09709173f 100644 --- a/ReactNativeClient/lib/models/BaseItem.js +++ b/ReactNativeClient/lib/models/BaseItem.js @@ -663,7 +663,12 @@ class BaseItem extends BaseModel { return super.save(o, options); } - static markdownTag(item) { + static markdownTag(itemOrId) { + const item = typeof itemOrId === 'object' ? itemOrId : { + id: itemOrId, + title: '', + }; + const output = []; output.push('['); output.push(markdownUtils.escapeLinkText(item.title));