I’m using ProseMirror to build a Markdown editor with support for
- Creating named regions in a Markdown file and
- Embedding a named region from
fileA.md
in a different filefileB.md
- When
fileB.md
is open, any edits to the embedded region should be saved tofileA.md
instead
My current solution for the embedded editor works like this:
- The embedded document is loaded in a
NodeView
which uses a nested ProseMirror instance - The NodeView loads the entire “embedded” document, creates an
EditorState
for it, and searches for the user-specified named region - The NodeView creates a separate
EditorState
object, and passes it to the nested ProseMirror editor - The
dispatchTransaction()
for the nested editor usesstate.tr.replaceWith
to apply changes made by the nested editor to the entire embedded document, so it can be properly saved
The problem is that it’s a bit inconvenient to have essentially two copies of the region’s state, since we need to keep them in sync. My questions are:
- Is there an easier way to restrict an EditorView to show only a slice / fragment / single node of a document?
- If not, does my approach sound reasonable, or might there be an easier way to accomplish the same thing?
Possible alternative solutions:
- Set
display:none
on all nodes outside of the restricted region, and use filterTransaction to make sure no edits change the frozen region
Related:
- Template-based Editor with Restricted Editing – however, as far as I can tell, this solution works by “freezing” parts of the document via filterTransaction, rather than hiding them