 
         # remove the firstAddedLine from the fragment
         firstAddedLine = dummyLine.lineNext
-        secondAddedLine = firstAddedLine.lineNext
-        frag.removeChild(frag.firstChild)
-        delete this._lines[firstAddedLine.lineID]
+        secondAddedLine = firstAddedLine?.lineNext
+        if frag.firstChild?
+            frag.removeChild(frag.firstChild)
+        if firstAddedLine?
+            delete this._lines[firstAddedLine.lineID]
 
         # 7- updates nextLine and prevLines, insert frag in the editor
         if secondAddedLine?

        
        @_deleteSelectedLines range
        @_addMissingFragment startLine, endOfLineFragment
        #startContainer = newStartContainer if newStartContainer?
        @_removeEndLine startLine, endLine
        @_adaptDepth startLine, startLineDepth, endLineDepth, deltaDepth
        if replaceCaret

                    txtNode = document.createTextNode(child.textContent)
                    
                    if context.currentLineEl.nodeName in ['SPAN','A']
                        context.currentLineEl.appendChild txtNode
                    else
                        spanEl = document.createElement('span')
                        spanEl.appendChild txtNode
                        context.currentLineEl.appendChild spanEl
                    
                    # @_appendCurrentLineFrag(context,absDepth,absDepth)
                    context.isCurrentLineBeingPopulated = true
