allow dragging only one note at a time

This commit is contained in:
azivner 2018-11-19 11:19:56 +01:00
parent fef4705e2f
commit 0c7ae527c5
2 changed files with 13 additions and 38 deletions

View file

@ -10,15 +10,13 @@ const dragAndDropSetup = {
node.setSelected(true);
const selectedNodes = treeService.getSelectedNodes().map(node => {
return {
// this is for dragging notes into relation map
// 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 is for dragging notes into relation map
data.dataTransfer.setData("text", JSON.stringify(selectedNodes));
}));
// This function MUST be defined to enable dragging for the tree.
// Return false to cancel dragging of node.

View file

@ -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 currentNoteId = treeService.getCurrentNode().data.noteId;
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;
return;
}
mapData.notes.push({noteId: note.noteId, x, y});
if (x - startX > 1000) {
x = startX;
y += 200;
}
else {
x += 200;
}
}
saveData();
await refresh();