         # what is incorrect when styles will be taken into account.
         targetNode   = currSel.range.startContainer
         startOffset  = currSel.range.startOffset
-        if targetNode.length
+        # if startContainer is a linediv, set targetNode to the inside text node
+        if targetNode.nodeName == 'DIV' and targetNode.id.substr(0,5)=='CNID_'
+            targetNode = targetNode.firstChild.firstChild
+            if startOffset > 0
+                startOffset = targetNode.length
+            else
+                startOffset = 0
             endOffset = targetNode.length - startOffset
-        else
-            endOffset = targetNode.childNodes.length - startOffset
-        i=0
-        
+        # if startContainer is a span, set targetNode to the inside text node
+        if targetNode.nodeName == 'SPAN'
+            targetNode = targetNode.firstChild
+            endOffset = targetNode.length - startOffset
+        # prepare lineElements
         if frag.childNodes.length > 0
             lineElements = frag.firstChild.childNodes
         else
             lineElements = [frag]
+        # loop on each element to insert (only one for now)
+        i=0
         nbElements = lineElements.length
         while i < nbElements-1
             elToInsert = lineElements[i]

            newLine$ = $("<div id='#{lineID}' class='#{p.targetLineType}-#{p.targetLineDepthAbs}'></div>")
            newLine$.append( $('<span></span><br>') )
        sourceLine = p.sourceLine
        newLine$   = newLine$.insertAfter(sourceLine.line$)
        newLine    =
            line$        : newLine$
            lineID       : lineID

    #     targetLineDepthRel : relative depth of the line to add
    ###
    _insertLineAfter : (p) ->
        
        # 1 - creation of the element of the line (newLine$)
        @_highestId += 1
        lineID          = 'CNID_' + @_highestId
        if p.fragment?
