@@ -998,6 +998,18 @@ socket.on('refresh', function (data) {
998998 lastchangeui = ui . infobar . lastchange ;
999999 updateLastChange ( ) ;
10001000 checkPermission ( ) ;
1001+ if ( ! loaded ) {
1002+ changeMode ( currentMode ) ;
1003+ loaded = true ;
1004+ emitUserStatus ( ) ; //send first user status
1005+ updateOnlineStatus ( ) ; //update first online status
1006+ setTimeout ( function ( ) {
1007+ //work around editor not refresh or doc not fully loaded
1008+ windowResizeInner ( ) ;
1009+ //work around might not scroll to hash
1010+ scrollToHash ( ) ;
1011+ } , 1 ) ;
1012+ }
10011013} ) ;
10021014
10031015var EditorClient = ot . EditorClient ;
@@ -1013,43 +1025,18 @@ socket.on('doc', function (obj) {
10131025
10141026 saveInfo ( ) ;
10151027 if ( bodyMismatch ) {
1028+ if ( cmClient )
1029+ cmClient . editorAdapter . ignoreNextChange = true ;
10161030 if ( body )
10171031 editor . setValue ( body ) ;
10181032 else
10191033 editor . setValue ( "" ) ;
10201034 }
1021- if ( ! cmClient ) {
1022- cmClient = window . cmClient = new EditorClient (
1023- obj . revision , obj . clients ,
1024- new SocketIOAdapter ( socket ) , new CodeMirrorAdapter ( editor )
1025- ) ;
1026- } else {
1027- cmClient . revision = obj . revision ;
1028- cmClient . initializeClients ( obj . clients ) ;
1029- if ( bodyMismatch ) {
1030- cmClient . undoManager . undoStack . length = 0 ;
1031- cmClient . undoManager . redoStack . length = 0 ;
1032- }
1033- }
10341035
10351036 if ( ! loaded ) {
10361037 editor . clearHistory ( ) ;
10371038 ui . spinner . hide ( ) ;
10381039 ui . content . fadeIn ( ) ;
1039- changeMode ( ) ;
1040- loaded = true ;
1041- emitUserStatus ( ) ; //send first user status
1042- updateOnlineStatus ( ) ; //update first online status
1043- setTimeout ( function ( ) {
1044- //work around editor not refresh
1045- editor . refresh ( ) ;
1046- //work around cursor not refresh
1047- for ( var i = 0 ; i < onlineUsers . length ; i ++ ) {
1048- buildCursor ( onlineUsers [ i ] ) ;
1049- }
1050- //work around might not scroll to hash
1051- scrollToHash ( ) ;
1052- } , 1 ) ;
10531040 } else {
10541041 //if current doc is equal to the doc before disconnect
10551042 if ( bodyMismatch )
@@ -1061,6 +1048,22 @@ socket.on('doc', function (obj) {
10611048 lastInfo . history = null ;
10621049 }
10631050
1051+ if ( ! cmClient ) {
1052+ cmClient = window . cmClient = new EditorClient (
1053+ obj . revision , obj . clients ,
1054+ new SocketIOAdapter ( socket ) , new CodeMirrorAdapter ( editor )
1055+ ) ;
1056+ } else {
1057+ if ( bodyMismatch ) {
1058+ cmClient . undoManager . undoStack . length = 0 ;
1059+ cmClient . undoManager . redoStack . length = 0 ;
1060+ }
1061+ cmClient . revision = obj . revision ;
1062+ cmClient . setState ( new ot . Client . Synchronized ( ) ) ;
1063+ cmClient . initializeClientList ( ) ;
1064+ cmClient . initializeClients ( obj . clients ) ;
1065+ }
1066+
10641067 if ( bodyMismatch ) {
10651068 isDirty = true ;
10661069 updateView ( ) ;
0 commit comments