     )
   )
 
-
-buildCursor = (userId, name, color) ->
+_buildCursor = (userId, name, color) ->
   cursor = @container.ownerDocument.createElement('span')
   cursor.setAttribute('contenteditable', false)
   cursor.classList.add('cursor')

        'top': '-18px'
        'white-space': 'nowrap'
      }
      '.cursor-inner': { 'display': 'inline-block', 'width': '2px', 'position': 'absolute', 'height': '15px', 'left': '-1px' }
      '.editor > .line:first-child .cursor-name': { 'border-top-left-radius': '0px', 'border-bottom-left-radius': '3px', 'top': '15px' }
    })
    @editor.on(Scribe.Editor.events.API_TEXT_CHANGE, (delta) =>
      applyDelta.call(this, delta)
    )
    @editor.on(Scribe.Editor.events.TEXT_CHANGE, (delta) =>
      applyDelta.call(this, delta)
    )

  shiftCursors: (index, length) ->

  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')
