Reply to: File changes lost when closing documentJanuary 25, 2013 at 2:08 am
So, you are setting ReadOnlyContainer on the document node (.DOCUMENT would be returned for the node name if you asked for range.ContainerNode right after the second line in your script). That node is a special node (something that probably only appears in our DOM and allows some APIs to do some special things — our CSS engine recognizes $DOCUMENT for the same node). The .DOCUMENT node contains the root element node.
The behaviour is working as designed. If you set that node to be a ReadOnlyContainer node the entire document becomes readonly (if you try to change it you are given a different message than if you set ReadOnlyContainer on the root element) and that functions slightly differently from setting ReadOnlyContainer on the root element. The assumption the API makes when you set it on .DOCUMENT is that it is impossible for the document to have been altered (and so the behaviour you are seeing is a fallout of that assumption).
I doubt that would be something we'd want to alter without having a really good reason for it as that is likely to spider out to affect other behaviours and APIs.
Can you change your logic so the document is saved right after the change (which I assume is actually being done in script)? After your script saves the document then you would set ReadOnlyContainer.