Improve the check for whether the CodeMirror should be cleaned up

When checking whether the wrapper element is still part of the DOM, check all the way up to the document body.
Currently, when removing an ancestor of the wrapper element from the DOM which is not its parent, the `resizeHandler` is not unregistered.