CM6 - Multiple docs with their own histories

Hello! I’m working on creating a prototype of the p5.js Editor that uses CM6. Super excited about all of the updated web accessibility features!

In CM5, I’m able to edit multiple files with their own undo/redo stack by creating a CodeMirror.Doc for each file, and then switching between those, depending on what the user is editing. I’m having a hard time figuring out how to do this in CM6. In the CM5 to 6 migration doc, it is suggested to create a new EditorState, but this also resets all of the extensions which is not ideal. Any suggestions for how to handle this in CM6 would be helpful, thank you!

Why is ‘resetting’ other extensions between separate documents not ideal? Which extension’s state would you want to share between the documents?

Maybe… it is totally okay? I guess I’m still mentally in CM5 and I’m just getting used to the new CM6 way. I think there’s a part of me that’s like, oh, I want these files to have the same configuration/extensions, like theme, indent, etc., but this configuration can just be duplicated across each state too.

Because in my web app users are able to change stuff like the theme, the only slightly annoying thing is that the theme extension will need to be updated across all of the states, but obviously this is manageable.

I tried creating a new EditorState for each file. One issue I am having is that when you make changes in the EditorView (like typing something), this does not change the doc in the EditorState. My expectation is that it would—do I need to manually create a transaction to update the EditorState in the EditorView.updateListener? Thank you!

Sounds like you’re expecting EditorState to be mutated when things happen in the editor. That’s an immutable value though. Track view.state if you want to get the current version of the state.

Ahhh that’s it! Thanks for your help.