         k = n - (m - (j + 1))
         if k > 0
             cursor = cm.getCursor()
-            cm.replaceRange(Array(k+1).join('\n'), {ch:0, line:m} )
+            cm.replaceRange(Array(k+1).join('\n'), {line:m+1, ch:0} )
             cm.setCursor(cursor)
 
     process_sage_updates: (start) =>

             worksheet = new Worksheet(@)

             code = mesg.javascript.code
             if mesg.javascript.coffeescript
                 code = CoffeeScript.compile(code)
             obj  = JSON.parse(mesg.obj)

             #console.log("executing script: '#{code}', obj='#{mesg.obj}'")


salvus_threejs = require("salvus_threejs")

account = require('account')


CLIENT_SIDE_MODE_LINES = []
for mode in ['md', 'html', 'coffeescript', 'javascript']
    for s in ['', '(hide=false)', '(hide=true)']
        CLIENT_SIDE_MODE_LINES.push("%#{mode}#{s}")

# Return true if there are currently unsynchronized changes, e.g., due to the network
# connection being down, or SageMathCloud not working, or a bug.
