 
     _sync: (cb) =>
         if @codemirror?  # need not be defined, right when user closes the editor instance
-            @_syncstring.set(@codemirror.getValue())
+            @_set_syncstring_to_codemirror()
         @_syncstring.save(cb)
 
     sync: (cb) =>

        @codemirror1 = @editor.codemirror1
        @element     = @editor.element

        # replace undo/redo by sync-aware versions
        for cm in [@codemirror, @codemirror1]
            cm.undo = @undo

            return
        cm = @focused_codemirror()  # see https://github.com/sagemathinc/smc/issues/1161
        if not @_syncstring.in_undo_mode()
            @_set_syncstring_to_codemirror()
        value = @_syncstring.undo()
        cm.setValueNoJump(value, true)
        @save_state_debounce()
