       @collectPathsForNode node
 
 #      console.log "Done. Updating mappings..."
-      parentPath = @parentPath path
-      parentPathInfo = @allPaths[parentPath]
-      parentMappings = @mappings[parentPath]
-      oldIndex = @mappings[path].start - parentMappings.start
-
-      @collectStrings node, path, parentPathInfo.content, parentMappings.start, oldIndex
+
+      if pathInfo.node is @pathStartNode
+        console.log "Ended up rescanning the whole doc."
+        @collectStrings node, path, null, 0, 0
+      else
+        parentPath = @parentPath path
+        parentPathInfo = @allPaths[parentPath]
+        unless parentPathInfo?
+          throw new Error "While performing update on node " + path + ", no path info found for parent path: " + parentPath
+        parentMappings = @mappings[parentPath]
+        unless parentMappings?
+          throw new Error "While performing update on node " + path + ", no mappings info found for parent path: " + parentPath
+        oldIndex = @mappings[path].start - parentMappings.start
+        @collectStrings node, path, parentPathInfo.content, parentMappings.start, oldIndex
+        
 #      console.log "Data update took " + (@timestamp() - startTime) + " ms."
 
     else

      children = node.childNodes
      range.setStartBefore children[0]
      range.setEndAfter children[children.length - 1]
    else
      range.setStartBefore node
      range.setEndAfter node

    sel.addRange range
    if scroll
      sn = node
      while not sn.scrollIntoViewIfNeeded?

#      console.log mappings

    mappings

  getContentForPath: (path = null) -> 
    path ?= @getDefaultPath()       
    @allPaths[path].content

  getLengthForPath: (path = null) ->
    path ?= @getDefaultPath()
    @allPaths[path].length

  getContentForRange: (start, end, path = null) ->
    @getContentForPath(path).substr start, end - start

  # Get the context that encompasses the given text range
  getContextForRange: (start, end) ->
    content = @getContentForPath()
    prefixStart = Math.max 0, start - CONTEXT_LEN
    prefixLen = start - prefixStart
    prefix = content.substr prefixStart, prefixLen
    suffix = content.substr end, prefixLen
    [prefix, suffix]
        

  # Get the matching DOM elements for a given text range
  # 
