Fix crash if document closed while custom command is executing