I’m trying to find the best way to switch between files so that changes and undo history are preserved. The goal is to emulate what you would expect form a traditional editor.
My initial approach was to reuse the same EditorView
instance and keep and EditorState
map in memory for each file and call view.setState(fileStateMap[filename]
) when the file is changed. But it looks like setState
resets the state itself.
Another approach could be to create an EditorView
instance for each file and attach/detach to the DOM when the file is changed. Not sure how this would scale if many files are opened.
Another approach is to store the text content and the history extension in a map for each file and dispatch a ReconfigurationSpec
with a tagged history extensions and changes to replace the text content.
Is there a “right” approach here or is there another approach that I’m missing?