Detecting MouseUp event when the mouse is not over an EditorWindow

Apparently an EditorWindow does not receive mouseUp events when the mouse is not over the window.

For example, in my EditorWindow, I start a drag selection on mouseDown and select items on mouseUp. It works fine if I release the mouse over the EditorWindow, but if I move off the window then release, the window never gets the mouseUp event, and I'm stuck in drag selection mode.

Is this expected behaviour? Is there a reliable workaround for this type of scenario?

I guess I could just kill the selection if the mouse moves off the window, but that's not what the user expects.

I was facing the same problem, and I finally found a solution that works for me, and hopefully would work for you as well.

Contrary to what you may believe, Event.type doesn’t just simply return the event’s type but among other things it filters out events of type MouseDown, MouseUp, DragPerformed, and DragUpdated and returns EventType.Ignore for the events happened outside of the current clipping region. This seems to be useful to make your window ignore mouse events happening outside of its client area or outside of a scroll view, but it’s certainly wrong in cases such these when MouseUp events get ignored.

Luckily, there’s a way to bypass this filtering using the Event.rawType property which simply returns the actual type of the event. So to handle MouseUp event you would have to set GUIUtility.hotControl to your control’s id on MouseDown and then catch the MouseUp with something like

if (GUIUtility.hotControl == myControlID && Event.current.rawType == EventType.MouseUp)
{
    Debug.Log("Yeah! MouseUp!");
}