From a30cd331dbcd59eab28072f3782f82b4408c195b Mon Sep 17 00:00:00 2001
From: Maximilian Giller <m.giller@tu-bs.de>
Date: Thu, 30 Jun 2022 16:45:44 +0200
Subject: [PATCH] Delete link on link click

---
 src/editor/js/components/editor.tsx | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/editor/js/components/editor.tsx b/src/editor/js/components/editor.tsx
index cf7c59b..c1ebd2b 100644
--- a/src/editor/js/components/editor.tsx
+++ b/src/editor/js/components/editor.tsx
@@ -9,6 +9,7 @@ import ReactForceGraph2d from "react-force-graph-2d";
 import { Node } from "../structures/graph/node";
 import { HistoryNavigator } from "./historynavigator";
 import { GraphElement } from "../structures/graph/graphelement";
+import { Link } from "../structures/graph/link";
 
 type propTypes = any;
 type stateTypes = {
@@ -50,6 +51,7 @@ export class Editor extends React.PureComponent<propTypes, stateTypes> {
         this.handleBackgroundClick = this.handleBackgroundClick.bind(this);
         this.handleNodeDrag = this.handleNodeDrag.bind(this);
         this.handleNodeDragEnd = this.handleNodeDragEnd.bind(this);
+        this.handleLinkClick = this.handleLinkClick.bind(this);
 
         this.renderer = React.createRef();
 
@@ -342,6 +344,11 @@ export class Editor extends React.PureComponent<propTypes, stateTypes> {
         return;
     }
 
+    private handleLinkClick(link: Link) {
+        link.delete();
+        this.forceUpdate();
+    }
+
     private handleEngineStop() {
         // Only do something on first stop for each graph
         if (this.warmupTicks <= 0) {
@@ -391,6 +398,7 @@ export class Editor extends React.PureComponent<propTypes, stateTypes> {
                             linkCanvasObjectMode={"replace"}
                             onNodeDrag={this.handleNodeDrag}
                             onNodeDragEnd={this.handleNodeDragEnd}
+                            onLinkClick={this.handleLinkClick}
                             onBackgroundClick={(event) =>
                                 this.handleBackgroundClick(
                                     event,
-- 
GitLab