rem: gEditor.insertText(repStr); 
add:    if (repStr == "") gEditor.deleteSelection(0); else gEditor.insertText(repStr);  
context: function onReplaceAll(){  if (!gEditor)    return;  var findStr = gReplaceDialog.findInput.value;  var repStr = gReplaceDialog.replaceInput.value;  // Transfer dialog contents to the find service.  saveFindData();  var finder = Components.classes["@mozilla.org/embedcomp/rangefind;1"].createInstance().QueryInterface(Components.interfaces.nsIFind);  finder.caseSensitive = gReplaceDialog.caseSensitive.checked;  finder.findBackwards = gReplaceDialog.searchBackwards.checked;  // Make a range containing the current selection,   // so we don't go past it when we wrap.  var selection = gEditor.selection;  var selecRange;  if (selection.rangeCount > 0)    selecRange = selection.getRangeAt(0);  var origRange = selecRange.cloneRange();  // We'll need a range for the whole document:  var wholeDocRange = gEditor.document.createRange();  var rootNode = gEditor.rootElement.QueryInterface(Components.interfaces.nsIDOMNode);  wholeDocRange.selectNodeContents(rootNode);  // And start and end points:  var endPt = gEditor.document.createRange();  if (gReplaceDialog.searchBackwards.checked)  {    endPt.setStart(wholeDocRange.startContainer, wholeDocRange.startOffset);    endPt.setEnd(wholeDocRange.startContainer, wholeDocRange.startOffset);  }  else  {    endPt.setStart(wholeDocRange.endContainer, wholeDocRange.endOffset);    endPt.setEnd(wholeDocRange.endContainer, wholeDocRange.endOffset);  }  // Find and replace from here to end of document:  var foundRange;  while ((foundRange = finder.Find(findStr, wholeDocRange,                                   selecRange, endPt)) != null)  {    gEditor.selection.removeAllRanges();    gEditor.selection.addRange(foundRange);    gEditor.insertText(repStr);    selection = gEditor.selection;    if (selection.rangeCount <= 0) {      return;    }    selecRange = selection.getRangeAt(0);  }  // If no wrapping, then we're done  if (!gReplaceDialog.wrap.checked)    return;  // If wrapping, find from start/end of document back to start point.  if (gReplaceDialog.searchBackwards.checked)  {    // Collapse origRange to end    origRange.setStart(origRange.endContainer, origRange.endOffset);    // Set current position to document end    selecRange.setEnd(wholeDocRange.endContainer, wholeDocRange.endOffset);    selecRange.setStart(wholeDocRange.endContainer, wholeDocRange.endOffset);  }  else  {    // Collapse origRange to start    origRange.setEnd(origRange.startContainer, origRange.startOffset);    // Set current position to document start    selecRange.setStart(wholeDocRange.startContainer,                        wholeDocRange.startOffset);    selecRange.setEnd(wholeDocRange.startContainer, wholeDocRange.startOffset);  }  while ((foundRange = finder.Find(findStr, wholeDocRange,                                   selecRange, origRange)) != null)  {    gEditor.selection.removeAllRanges();    gEditor.selection.addRange(foundRange);    gEditor.insertText(repStr);    selection = gEditor.selection;    if (selection.rangeCount <= 0) {      return;    }    selecRange = selection.getRangeAt(0);  }}
meta: 5459	/local1/tlutelli/issta_data/temp/all_js/javascript/2006_temp/2006/5459/3227b82c704df53da63092d71df11c9f26027528/EdReplace.js/buggy/editor/ui/dialogs/content/EdReplace.js