   cursor.appendChild(inner)
   return cursor
 
+_setCursor = (userId, index, name, color) ->
+  @editor.doSilently( =>
+    @cursors[userId] = { name: name, color: color, userId: userId } unless @cursors[userId]?
+    @cursors[userId].index = index
+    cursor = @container.querySelector("##{Scribe.Editor.CURSOR_PREFIX}#{userId}")
+    if cursor?
+      cursor.querySelector('.cursor-name').classList.remove('hidden')
+    else
+      cursor = _buildCursor.call(this, userId, name, color)
+      @container.appendChild(cursor)
+    position = new Scribe.Position(@editor, index)
+    if !position.leafNode.firstChild?
+      cursor.style.top = position.leafNode.parentNode.offsetTop
+      cursor.style.left = position.leafNode.parentNode.offsetLeft
+    else
+      [leftText, rightText, didSplit] = Scribe.DOM.splitNode(position.leafNode.firstChild, position.offset)
+      if rightText?
+        span = @container.ownerDocument.createElement('span')
+        Scribe.DOM.wrap(span, rightText)
+        cursor.style.top = span.offsetTop
+        cursor.style.left = span.offsetLeft
+        Scribe.DOM.unwrap(span)
+      else if leftText?
+        span = @container.ownerDocument.createElement('span')
+        leftText.parentNode.parentNode.appendChild(span)
+        cursor.style.top = span.offsetTop
+        cursor.style.left = span.offsetLeft
+        span.parentNode.removeChild(span)
+      position.leafNode.normalize() if didSplit
+  )
+
 
 class ScribeMultiCursorManager
+  @CURSOR_NAME_TIMEOUT: 5000
+
   constructor: (@editor) ->
     @cursors = {}
     @container = @editor.root.ownerDocument.createElement('div')

applyDelta = (delta) ->
  _.defer( =>
    delta.apply((index, text) =>
      this.shiftCursors(index, text.length)

      return if cursor == undefined || cursor.index < index
      if (cursor.index >= index)
        if length > 0
          _setCursor.call(this, cursor.userId, cursor.index + length, cursor.name, cursor.color)   # Insert
        else
          # Delete needs to handle special case: start|cursor|end vs normal case: start|end|cursor
          _setCursor.call(this, cursor.userId, cursor.index + Math.max(length, index - cursor.index), cursor.name, cursor.color)
    )

  setCursor: (userId, index, name, color) ->
    _setCursor.call(this, userId, index, name, color)
    clearTimeout(@cursors[userId].timer)
    @cursors[userId].timer = setTimeout( =>
      cursorName = @container.querySelector("##{Scribe.Editor.CURSOR_PREFIX}#{userId} .cursor-name")
      cursorName.classList.add('hidden') if cursorName
      @cursors[userId].timer = null
    , Scribe.MultiCursorManager.CURSOR_NAME_TIMEOUT)

  clearCursors: ->
    while @container.firstChild?
