The event textViewLocationChanged returns the current scroll location which is stored in the variable scrollLocation. The dummy function insertComplexElement stores the current scroll location in the variable freezedScrollLocation before it is sending the document to the server. After the document has been retrieved from the server, it is loaded and the scroll location is restored using the command ScrollDelta. In order to use this code, it is required to turn on the hidden command interface which is done using the enableCommands method.
How to load and save documents from and to the MVC controller can be found in this article: