public override void HandleMouseUp(MouseUpEvent evt)
        {
            bool didConnect = false;

            Vector2 mousePosition = evt.mousePosition;

            // Reset the highlights.
            graphView.ports.ForEach((p) => {
                p.OnStopEdgeDragging();
            });

            // Clean up ghost edges.
            if (ghostEdge != null)
            {
                if (ghostEdge.input != null)
                {
                    ghostEdge.input.portCapLit = false;
                }
                if (ghostEdge.output != null)
                {
                    ghostEdge.output.portCapLit = false;
                }

                graphView.RemoveElement(ghostEdge);
                ghostEdge.input  = null;
                ghostEdge.output = null;
                ghostEdge        = null;
            }

            Port endPort = GetEndPort(mousePosition);

            if (endPort == null && listener != null)
            {
                listener.OnDropOutsidePort(edgeCandidate, mousePosition);
            }

            edgeCandidate.SetEnabled(true);

            if (edgeCandidate.input != null)
            {
                edgeCandidate.input.portCapLit = false;
            }

            if (edgeCandidate.output != null)
            {
                edgeCandidate.output.portCapLit = false;
            }

            // If it is an existing valid edge then delete and notify the model (using DeleteElements()).
            if (edgeCandidate.input != null && edgeCandidate.output != null)
            {
                // Save the current input and output before deleting the edge as they will be reset
                Port oldInput  = edgeCandidate.input;
                Port oldOutput = edgeCandidate.output;

                graphView.DeleteElements(new[] { edgeCandidate });

                // Restore the previous input and output
                edgeCandidate.input  = oldInput;
                edgeCandidate.output = oldOutput;
            }
            // otherwise, if it is an temporary edge then just remove it as it is not already known my the model
            else
            {
                graphView.RemoveElement(edgeCandidate);
            }

            if (endPort != null)
            {
                if (endPort.direction == Direction.Output)
                {
                    edgeCandidate.output = endPort;
                }
                else
                {
                    edgeCandidate.input = endPort;
                }

                listener.OnDrop(graphView, edgeCandidate);
                didConnect = true;
            }
            else
            {
                edgeCandidate.output = null;
                edgeCandidate.input  = null;
            }

            edgeCandidate.ResetLayer();

            edgeCandidate = null;
            compatiblePorts.Clear();
            Reset(didConnect);
        }