Browse Source

Fix bug in GraphState module

Joeri Exelmans 1 year ago
parent
commit
63e172ea3e
1 changed files with 4 additions and 2 deletions
  1. 4 2
      src/onion/graph_state.ts

+ 4 - 2
src/onion/graph_state.ts

@@ -563,18 +563,20 @@ export class GraphState {
     }
     // Delete link to new target (if there is a target)
     const newTarget = delta.target.getTarget();
+    const oldTarget = overwrittenEdgeOperation.target.getTarget();
     if (newTarget !== null) {
       // The new target is a node
       const newTargetState = this._getEdgeTargetState(newTarget);
       // Add to new target's incoming edges
       if (newTargetState !== undefined) {
-        newTargetState.removeIncoming(delta, listener);
+        if (newTarget !== oldTarget) { // if newTarget === oldTarget, the 'delta' does not have to be removed from 'incoming' (it will be replaced when dealing with 'oldTarget')
+          newTargetState.removeIncoming(delta, listener);
+        }
         newTargetState.incomingStates.splice(newTargetState.incomingStates.findIndex(([l,s]) => l===label && s===sourceState), 1);
         listener.deleteLink(sourceId, label);
       }
     }
     // Restore link to old target
-    const oldTarget = overwrittenEdgeOperation.target.getTarget();
     if (oldTarget !== null) {
       // The old target was a node
       const oldTargetState = this._getEdgeTargetState(oldTarget);