       sn.scrollIntoViewIfNeeded()
     sel
 
+  # Read and convert the text of the current selection.
+  readSelectionText: (sel) ->
+    sel or= @rootWin.getSelection()
+    sel.toString().trim().replace(/\n/g, " ").replace /[ ][ ]+/g, " "
+
   # Read the "text content" of a sub-tree of the DOM by creating a selection from it
   getNodeSelectionText: (node, shouldRestoreSelection = true) ->
     if shouldRestoreSelection then @saveSelection()
 
     sel = @selectNode node
-
-    # read (and convert) the content of the selection
-    text = sel.toString().trim().replace(/\n/g, " ").replace /[ ][ ]+/g, " "
+    text = @readSelectionText sel
 
     if shouldRestoreSelection then @restoreSelection()
     text

      delete result.pathInfo.node
    result

  # Get the matching DOM elements for a given set of text ranges
  # (Calles getMappingsForRange for each element in the givenl ist)
  getMappingsForRanges: (ranges, path = null) ->

    suffix = content.substr end, prefixLen
    [prefix.trim(), suffix.trim()]
        
  # Get the matching DOM elements for a given text range
  # 
  # If the "path" argument is supplied, scan is called automatically.
