           (head.container.start.next.type is 'text' or head.container.start.next is head.container.end)
         head = head.next
       if head?
-        if @textFocus? and head.container.hasParent @textFocus.parent
-          persistentParent = @textFocus.getCommonParent(head.container).parent
-
-          chars = getCharactersTo persistentParent, head.container.start
+        # Avoid problems with reparses by getting text offset location
+        # of the given socket before reparsing and recovering it afterward.
+        if @textFocus?
+          chars = @getCharactersTo head.container.start
           @setTextInputFocus null
-          socket = getSocketAtChar persistentParent, chars
+          socket = @getSocketAtChar chars
         else
           socket = head.container
           @setTextInputFocus null

        # Now that we've done that, we can annul stuff.
        @endDrag()

  Editor::reparseRawReplace = (oldBlock) ->
    try
      newParse = @mode.parse(oldBlock.stringify(@mode), wrapAtRoot: true)
      newBlock = newParse.start.next.container


      if head.type is 'socketStart' and
          (head.next.type is 'text' or head.next is head.container.end)
        # Avoid problems with reparses by getting text offset location
        # of the given socket before reparsing and recovering it afterward.
        if @textFocus?
          chars = @getCharactersTo head.container.start
          @setTextInputFocus null
          socket = @getSocketAtChar chars
        else
          socket = head.container
          @setTextInputFocus null
