       if @textFocus? then head = @textFocus.start
       else head = @cursor
 
-      until (not head?) or head.type is 'socketEnd' and head.container.start.next.type is 'text'
-        head = head.prev
+      until (not head?) or head.type is 'socketStart' and
+          (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.parent.parent

      head = head.prev

    return chars
  
  getSocketAtChar = (parent, chars) ->
    head = parent.start
    charsCounted = 0

      if @textFocus? then head = @textFocus.end
      else head = @cursor

      until (not head?) or head.type is 'socketStart' and
          (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
