mirror of
https://github.com/zadam/trilium.git
synced 2025-01-18 21:22:56 +08:00
allow dragging only one note at a time
This commit is contained in:
parent
fef4705e2f
commit
0c7ae527c5
2 changed files with 13 additions and 38 deletions
|
@ -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.
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue