Y-monaco - multiple files

Hi! With Monaco I can work with multiple files (tabs) by creating a model for each. I am trying to figure out a way to work with multiple files with y-Monaco (even if it’s just one file at a time). I’d rather not overwrite the contents with each file and lose the edit history. If there an example of how to do this?

It looks like you bind Monaco to a type, just looking for a way to switch between a pool of types without loosing history.


Hi @timcubb,

y-monaco binds a Y.Text to an ITextModel. ITextModel represents a specific document and maintains its own history. You can simply switch to a different ITextModel and render that without losing history from other documents. This is how VSCode implements tabs: When you click on a tab, the monaco editor renders the associated ITextModel. You simply need to maintain the editor bindings alongside.

This documentation shows how you bind a Y.Text type to a specific model: https://github.com/yjs/y-monaco/

This documentation shows how you can maintain a list of documents in a single Yjs instance: https://docs.yjs.dev/getting-started/working-with-shared-types#managing-multiple-collaborative-documents-in-a-shared-type I think this is what you are looking for. You simply need to adapt the example and add some additional complexity to enable opening and closing of tabs.

1 Like