Skip to content

Build your personal knowledge base with Trilium Notes

allow dragging only one note at a time

azivner0c7ae527c564
diff --git a/src/public/javascripts/services/drag_and_drop.js b/src/public/javascripts/services/drag_and_drop.js
index 0abd52cc81..6b0cef6682 100644
--- a/src/public/javascripts/services/drag_and_drop.js
+++ b/src/public/javascripts/services/drag_and_drop.js
@@ -10,15 +10,13 @@ const dragAndDropSetup = {
node.setSelected(true);
- const selectedNodes = treeService.getSelectedNodes().map(node => {
- return {
- noteId: node.data.noteId,
- title: node.title
- }
- });
-
// this is for dragging notes into relation map
- data.dataTransfer.setData("text", JSON.stringify(selectedNodes));
+ // we allow to drag only one note at a time because it multi-drag conflicts with multiple single drags
+ // in UX and single drag is probably more useful
+ data.dataTransfer.setData("text", JSON.stringify({
+ noteId: node.data.noteId,
+ title: node.title
+ }));
// This function MUST be defined to enable dragging for the tree.
// Return false to cancel dragging of node.
diff --git a/src/public/javascripts/services/note_detail_relation_map.js b/src/public/javascripts/services/note_detail_relation_map.js
index 7e620495ac..a90a744ea4 100644
--- a/src/public/javascripts/services/note_detail_relation_map.js
+++ b/src/public/javascripts/services/note_detail_relation_map.js
@@ -522,43 +522,20 @@ function getZoom() {
async function dropNoteOntoRelationMapHandler(ev) {
ev.preventDefault();
- const notes = JSON.parse(ev.originalEvent.dataTransfer.getData("text"));
+ const note = JSON.parse(ev.originalEvent.dataTransfer.getData("text"));
let {x, y} = getMousePosition(ev);
- // modifying position so that cursor is on the top-center of the box
- const startX = x -= 80;
- y -= 15;
+ const exists = mapData.notes.some(n => n.noteId === note.noteId);
- const currentNoteId = treeService.getCurrentNode().data.noteId;
+ if (exists) {
+ await infoDialog.info(`Note "${note.title}" is already placed into the diagram`);
- for (const note of notes) {
- if (note.noteId === currentNoteId) {
- // we don't allow placing current (relation map) into itself
- // the reason is that when dragging notes from the tree, the relation map is always selected
- // since it's focused.
- continue;
- }
-
- const exists = mapData.notes.some(n => n.noteId === note.noteId);
-
- if (exists) {
- await infoDialog.info(`Note "${note.title}" is already placed into the diagram`);
-
- continue;
- }
-
- mapData.notes.push({noteId: note.noteId, x, y});
-
- if (x - startX > 1000) {
- x = startX;
- y += 200;
- }
- else {
- x += 200;
- }
+ return;
}
+ mapData.notes.push({noteId: note.noteId, x, y});
+
saveData();
await refresh();