Handle the case when the editor is destroyed while dragging

Closes #4622