     @setSelectionRange(range)
     # TODO: move to TextManager
     if text != ''
-      try # Firefox sometime throws exceptions on inserting '\n', even if we fist call delete, so we need to ignore this :-(
+      try
+        # Firefox sometime throws exceptions on inserting '\n', even if we fist call delete,
+        # so we need to ignore these :-(
         document.execCommand 'insertText', false, text
       catch
     else

  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


    @setSelectionRange [@positionForCharacterIndex(selStartIx), @positionForCharacterIndex(selEndIx)]

    # TODO: check if okay when selection was null

  positionForCharacterIndex: (ix) ->
    bufferText = @getText()
