     head = parent.start
     charsCounted = 0
 
-    until charsCounted >= chars and head.type is 'socketStart' and head.next.type is 'text'
+    until charsCounted >= chars and head.type is 'socketStart' and
+        (head.next.type is 'text' or head.next is head.container.end)
       if head.type is 'text' then charsCounted += head.value.length
 
       head = head.next

              parseParent.start.prev.append newParse
              newParse.container.end.append parseParent.end.next

              newParse.parent = newParse.start.parent = newParse.end.parent =
                parseParent.parent

              newParse.notifyChange()

              @addMicroUndoOperation new ReparseOperation parseParent, newParse.container


          persistentParent = @textFocus.parent.parent

          chars = getCharactersTo persistentParent, head.container.start
          console.log 'chars:', chars
          @setTextInputFocus null
          socket = getSocketAtChar persistentParent, chars
        else
