A code editor edits files. I'm calling the data representation of these files in the browser client as model.
We actually create a root doc for a given filePath only once and all CM instances (e.g. in tabs / references) pointing to the same path get a linked version of the same doc. This gives us unified history / change tracking by filePath.
Keeping the file up to date with server changes
The doc cache sends any edits to the root document to the server. The doc cache also subscribes to server edits / file save changes and updates the rootDoc.
The docCache makes sure that edits that were created locally aren't applied by adding an
originId to code edits.
originId is unique by each browser window. If the server sends us an edit with the same
originId it means we did that edit and we do just ignore it. Other edits sent by the server is mapped to
sourceId before making the edit to the local root doc so that when the
change fires on the doc we just ignore it (as all relevant syncing is complete). The following demonstrates a multi-monitor/multi-browser-window demo working just fine.