From 355a2a7bf8fab5b0a763b31a2ffa02f48ed68783 Mon Sep 17 00:00:00 2001 From: Maximilian Giller <m.giller@tu-bs.de> Date: Fri, 7 Jan 2022 15:57:58 +0100 Subject: [PATCH] Implemented deletion with selection box --- editor/js/tools/deletetool.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/editor/js/tools/deletetool.js b/editor/js/tools/deletetool.js index 97a420b..44cfdc3 100644 --- a/editor/js/tools/deletetool.js +++ b/editor/js/tools/deletetool.js @@ -21,7 +21,7 @@ export default class DeleteTool extends Tool { onBoxSelect(left, bottom, top, right) { // Filter out selected nodes - const hitNodes = []; + const selectedNodes = []; const tl = renderer.screen2GraphCoords(left, top); const br = renderer.screen2GraphCoords(right, bottom); graph.data[Graph.GRAPH_NODES].forEach((node) => { @@ -31,13 +31,25 @@ export default class DeleteTool extends Tool { br.y > node.y && node.y > tl.y ) { - hitNodes.push(node); + selectedNodes.push(node); } }); - // Delete selected items after confirmation - console.log("DELETE"); - console.log(hitNodes); + // Was anything even selected? + if (selectedNodes.length <= 0) { + return; + } + + // Ask for confirmation to delete + var nodeNames = selectedNodes.map((n) => n[Graph.NODE_LABEL]); + //! Problem: If browser is not actually showing the alerts, it always returns false! + var shouldDelete = confirm("Do you wanna delete all these nodes:\n\n" + nodeNames.join("\n")) + + // Delete if confirmed + if (shouldDelete) { + var nodeIds = selectedNodes.map((n) => n[Graph.NODE_ID]); + graph.deleteNodes(nodeIds); + } } onNodeClick(node) { -- GitLab