     winSelection.removeAllRanges()
     winSelection.addRange docRange
 
-  # TODO: use point or array
-  getNodeAndOffsetForPos: (rowNr, colNr) ->
-    console.log "getNodeAndOffsetForPos: #{rowNr} #{colNr}"
-    nodeLines = @getNodeLines()
-    nodeLine = nodeLines[rowNr]
-    relativeCol = colNr
-    for node, i in nodeLine
-      if node.nodeType == Node.TEXT_NODE
-        textLen = node.textContent.length
-        if relativeCol <= textLen
-          return [node, relativeCol]
-        else
-          relativeCol -= textLen
-      else if node.nodeType == Node.ELEMENT_NODE && node.tagName == 'BR'
-        return [node, 0]
-        break;
-      else # We should only have text and a single <br>
-         console.error 'getNodeAndOffsetForPos: unhandled node type or tagName: ' + node.nodeType + ' & ' + node.tagName
-    ## TODO: handle beyond end of line, and don't return br, but simply last text elt
-    return null
-
-  getText: ->
-    textLines =
-      for nodeLine in @getNodeLines()
-        _.map nodeLine, (n) -> if n.nodeType == Node.TEXT_NODE then n.textContent else ''
-          .join('')
-    textLines.join('\n')
-
-  setText: (txt) ->
-    @$editableDiv.empty()
-    for line in txt.split '\n'
-      lineDiv = $('<div>').text line
-      @$editableDiv.append lineDiv
-
-class Buffer
-  textManager: null
-
-  constructor: ($editableDiv) ->
-    @textManager = new TextManager($editableDiv)
-
-  getText: ->
-    @textManager.getText()
-
-  setText: (txt) ->
-    @textManager.setText txt
-
-  getSelectionRange: ->
-    [anchorPos,focusPos] = @textManager.getSelectionPoss()
-    new Range( [anchorPos[0], anchorPos[1]], [focusPos[0], focusPos[1]] )
-
-  setSelectionRange: (range) ->
-    range = Range.fromObj(range)
-    [startNode, startOffset] = @textManager.getNodeAndOffsetForPos range.start.row, range.start.column
-    [endNode,   endOffset]   = @textManager.getNodeAndOffsetForPos range.end.row, range.end.column
-    @textManager.setDocSelection startNode, startOffset, endNode, endOffset
 
   delete: (range) ->
     @setTextInRange range, ''

  constructor: ($editableDiv) ->
    @$editableDiv = $editableDiv

  getNodeLines: ->
    root = @$editableDiv[0]
    @traverse root.childNodes

  # span inserted by Chrome
  # <br> at end of line is used for selection, by Chrome, but selection at and of preceding text elt also works

  # TODO: check if this is really the case, and this thing works
  # because newlines are always encoded with a br (todo, maybe newline when we implement is) we don't have to
  # recreate complex line break patterns of nested divs and spans
  traverse: (nodes) ->
    nodeLines = []
    currentLine = []
    for node,i in nodes
      # console.log node,i
      switch node.nodeType
        when Node.TEXT_NODE
          # console.log '### text'
          currentLine.push node
        when Node.ELEMENT_NODE
          switch node.tagName
            when 'DIV'
              # console.log 'div'
              if currentLine.length > 0
                nodeLines.push currentLine
                currentLine = []
              nodeLines = nodeLines.concat @traverse node.childNodes
              # console.log 'd' + @showNodeLines traverse node.childNodes
            when 'SPAN'
              spanNodeLines = @traverse node.childNodes
              if spanNodeLines.length > 0
                currentLine = currentLine.concat spanNodeLines[0]
              if spanNodeLines.length > 1
                console.log 'WEIRD: line break in span'
                # TODO: check these
                nodeLines.push currentLine
                nodeLines = nodeLines.concat _.init spanNodeLines
                currentLine = _.last spanNodeLines
            when 'BR'
              currentLine.push node

    if currentLine.length > 0
      nodeLines.push currentLine
      currentLine = []
    nodeLines

  showNodeLines: (nodeLines) ->
