I have been reading papers on this looking for a "clean" way to solve this (in the context of packet loss, latency, etc).
One good approach I was able to understand is Neil Fraser's Differential Sync http://neil.fraser.name/writing/sync/eng047-fraser.pdf
There are other approaches out there. One example which uses character based changes and is worth checking out is here: PAPER wikisym.org/ws2010/tiki-download_wiki_attachment.php?attId=15 CODE https://github.com/gritzko/ctre
I feel like it is time someone solved this collab. editing thing once and for all and shared the code with everyone. (Firepad? https://github.com/firebase/firepad/)