rem:     var tmpNode; if (endContainer.nodeType == Node.TEXT_NODE || endContainer.nodeType == Node.CDATA_SECTION_NODE) {      if ((endOffset > 0 && endOffset < endContainer.data.length) || !endContainer.parentNode || !endContainer.parentNode.parentNode) endContainer.insertData(endOffset, MARK_SELECTION_END); 
add:    var canDrawSelection = ancestorContainer.hasChildNodes(); if (canDrawSelection) { var i; for (i = startPath ? startPath.length-1 : -1; i >= 0; i--) { startContainer = startContainer.childNodes.item(startPath[i]); } for (i = endPath ? endPath.length-1 : -1; i >= 0; i--) { endContainer = endContainer.childNodes.item(endPath[i]); }      var tmpNode; if (endContainer.nodeType == Node.TEXT_NODE || endContainer.nodeType == Node.CDATA_SECTION_NODE) {      if ((endOffset > 0 && endOffset < endContainer.data.length) || !endContainer.parentNode || !endContainer.parentNode.parentNode) endContainer.insertData(endOffset, MARK_SELECTION_END); else { tmpNode = doc.createTextNode(MARK_SELECTION_END); endContainer = endContainer.parentNode; if (endOffset == 0) endContainer.parentNode.insertBefore(tmpNode, endContainer); else endContainer.parentNode.insertBefore(tmpNode, endContainer.nextSibling); } } 
context: function viewPartialSourceForSelection(selection){  var range = selection.getRangeAt(0);  var ancestorContainer = range.commonAncestorContainer;  var doc = ancestorContainer.ownerDocument;  var startContainer = range.startContainer;  var endContainer = range.endContainer;  var startOffset = range.startOffset;  var endOffset = range.endOffset;  // let the ancestor be an element  if (ancestorContainer.nodeType == Node.TEXT_NODE ||      ancestorContainer.nodeType == Node.CDATA_SECTION_NODE)    ancestorContainer = ancestorContainer.parentNode;  // for selectAll, let's use the entire document, including <html>...</html>  // @see DocumentViewerImpl::SelectAll() for how selectAll is implemented  try {    if (ancestorContainer == doc.body)      ancestorContainer = doc.documentElement;  } catch (e) { }  // each path is a "child sequence" (a.k.a. "tumbler") that  // descends from the ancestor down to the boundary point  var startPath = getPath(ancestorContainer, startContainer);  var endPath = getPath(ancestorContainer, endContainer);  // clone the fragment of interest and reset everything to be relative to it  // note: it is with the clone that we operate from now on  ancestorContainer = ancestorContainer.cloneNode(true);  startContainer = ancestorContainer;  endContainer = ancestorContainer;  var i;  for (i = startPath ? startPath.length-1 : -1; i >= 0; i--) {    startContainer = startContainer.childNodes.item(startPath[i]);  }  for (i = endPath ? endPath.length-1 : -1; i >= 0; i--) {    endContainer = endContainer.childNodes.item(endPath[i]);  }  // add special markers to record the extent of the selection  // note: |startOffset| and |endOffset| are interpreted either as  // offsets in the text data or as child indices (see the Range spec)  // (here, munging the end point first to keep the start point safe...)  var tmpNode;  if (endContainer.nodeType == Node.TEXT_NODE ||      endContainer.nodeType == Node.CDATA_SECTION_NODE) {    // do some extra tweaks to try to avoid the view-source output to look like    // ...<tag>]... or ...]</tag>... (where ']' marks the end of the selection).    // To get a neat output, the idea here is to remap the end point from:    // 1. ...<tag>]...   to   ...]<tag>...    // 2. ...]</tag>...  to   ...</tag>]...    if ((endOffset > 0 && endOffset < endContainer.data.length) ||        !endContainer.parentNode || !endContainer.parentNode.parentNode)      endContainer.insertData(endOffset, MARK_SELECTION_END);    else {      tmpNode = doc.createTextNode(MARK_SELECTION_END);      endContainer = endContainer.parentNode;      if (endOffset == 0)        endContainer.parentNode.insertBefore(tmpNode, endContainer);      else        endContainer.parentNode.insertBefore(tmpNode, endContainer.nextSibling);    }  }  else {    tmpNode = doc.createTextNode(MARK_SELECTION_END);    endContainer.insertBefore(tmpNode, endContainer.childNodes.item(endOffset));  }  if (startContainer.nodeType == Node.TEXT_NODE ||      startContainer.nodeType == Node.CDATA_SECTION_NODE) {    // do some extra tweaks to try to avoid the view-source output to look like    // ...<tag>[... or ...[</tag>... (where '[' marks the start of the selection).    // To get a neat output, the idea here is to remap the start point from:    // 1. ...<tag>[...   to   ...[<tag>...    // 2. ...[</tag>...  to   ...</tag>[...    if ((startOffset > 0 && startOffset < startContainer.data.length) ||        !startContainer.parentNode || !startContainer.parentNode.parentNode ||        startContainer != startContainer.parentNode.lastChild)      startContainer.insertData(startOffset, MARK_SELECTION_START);    else {      tmpNode = doc.createTextNode(MARK_SELECTION_START);      startContainer = startContainer.parentNode;      if (startOffset == 0)        startContainer.parentNode.insertBefore(tmpNode, startContainer);      else        startContainer.parentNode.insertBefore(tmpNode, startContainer.nextSibling);    }  }  else {    tmpNode = doc.createTextNode(MARK_SELECTION_START);    startContainer.insertBefore(tmpNode, startContainer.childNodes.item(startOffset));  }  // now extract and display the syntax highlighted source  tmpNode = doc.createElementNS(NS_XHTML, 'div');  tmpNode.appendChild(ancestorContainer);  // the load is aynchronous and so we will wait until the view-source DOM is done  // before drawing the selection.  window.document.getElementById("appcontent").addEventListener("load", drawSelection, true);  // all our content is held by the data:URI and URIs are internally stored as utf-8 (see nsIURI.idl)  var loadFlags = Components.interfaces.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE;  getBrowser().webNavigation              .loadURI("view-source:data:text/html;charset=utf-8," + encodeURIComponent(tmpNode.innerHTML),                       loadFlags, null, null, null);}
meta: 9421	/local1/tlutelli/issta_data/temp/all_js/javascript/2006_temp/2006/9421/0893894d7555f9104bb2410c5441264ad84204ee/viewPartialSource.js/clean/xpfe/browser/resources/content/viewPartialSource.js