How to get left mouse up event in an EditorTool?

I am making my own editor tool but for some reason I never get the left mouse button up event.

This is my code:

public override void OnToolGUI(EditorWindow window)
{
    Event e = Event.current;
    if (e.type == EventType.Layout || e.type == EventType.Repaint)
        return;
    var type = e.type;
    if (type == EventType.MouseDown)
        Debug.Log("Mouse Down.");
    if (type == EventType.MouseDrag)
        Debug.Log("Mouse Dragged.");
    if (type == EventType.MouseUp)
        Debug.Log("Mouse Up.");
}

Debug Log:

image

The output gives me Mouse Down but never Mouse Up. Yet for right clicks I get both Mouse Down and Mouse Up. Why is this?

Is Unity’s built in tools using the mouse up for left clicks? If so how do i also listen for it?

To detect the left mouse button up event in an Editor Tool, you can use the EventType.MouseDrag event along with a boolean flag to track whether the left mouse button was pressed.

public class MyEditorTool : EditorWindow
{
    private bool leftMouseButtonDown = false;

    public override void OnToolGUI(EditorWindow window)
    {
        Event e = Event.current;
        if (e.type == EventType.Layout || e.type == EventType.Repaint)
            return;

        var type = e.type;

        if (type == EventType.MouseDown && e.button == 0) // Check for left mouse button down
        {
            Debug.Log("Mouse Down.");
            leftMouseButtonDown = true;
        }

        if (type == EventType.MouseDrag && e.button == 0) // Check for left mouse button drag
        {
            Debug.Log("Mouse Dragged.");
        }

        if (type == EventType.MouseUp && e.button == 0 && leftMouseButtonDown) // Check for left mouse button up
        {
            Debug.Log("Mouse Up.");
            leftMouseButtonDown = false; // Reset the flag after detecting the mouse up
        }
    }
}