I’ve adapted the approach that johanneswilm describes (adding a top-level node under the doc node), but have discovered some issues with it:
- Select-all (e.g. mod-a) and delete removes the top level node, clearing any data stored in it.
- Delete or backspace at the correct positions in an empty document can delete the top-level node.
I’ve tried making the node unselectable in the schema, but that didn’t help.
The data I’m storing in this top-level node would be better suited to a plugin’s state, but in my case it’s conceptually part of the document, and the document is what I’m storing. i.e. I’m serializing the document node - not the entire state - for storage, and using the document change as a trigger for storing being necessary (only the document is exposed to external code). Having plugin state be at the same level as the doc and selection makes this more complex.