When creating a new, empty XQuery, mark it as saved and disable validation. Closing the document in this state will not ask for confirmation. Start validation and mark the document as changed only after the user typed something.