зеркало из https://github.com/mozilla/pjs.git
116405: Fix replace all, backwards case. r=jfrancis sr=sfraser a=asa
This commit is contained in:
Родитель
6a5abab113
Коммит
67b4b615a9
|
@ -227,7 +227,7 @@ function onReplaceAll()
|
||||||
|
|
||||||
var finder = Components.classes["@mozilla.org/embedcomp/rangefind;1"].createInstance().QueryInterface(Components.interfaces.nsIFind);
|
var finder = Components.classes["@mozilla.org/embedcomp/rangefind;1"].createInstance().QueryInterface(Components.interfaces.nsIFind);
|
||||||
|
|
||||||
finder.caseSensitive = gReplaceDialog.caseSensitive.checked;
|
finder.caseSensitive = gReplaceDialog.caseSensitive.checked;
|
||||||
finder.findBackwards = gReplaceDialog.searchBackwards.checked;
|
finder.findBackwards = gReplaceDialog.searchBackwards.checked;
|
||||||
|
|
||||||
// Make a range containing the current selection,
|
// Make a range containing the current selection,
|
||||||
|
@ -244,13 +244,18 @@ function onReplaceAll()
|
||||||
wholeDocRange.selectNodeContents(rootNode);
|
wholeDocRange.selectNodeContents(rootNode);
|
||||||
|
|
||||||
// And start and end points:
|
// And start and end points:
|
||||||
var startPt = gEditor.document.createRange();
|
|
||||||
startPt.setStart(wholeDocRange.startContainer, wholeDocRange.startOffset);
|
|
||||||
startPt.setEnd(wholeDocRange.startContainer, wholeDocRange.startOffset);
|
|
||||||
|
|
||||||
var endPt = gEditor.document.createRange();
|
var endPt = gEditor.document.createRange();
|
||||||
endPt.setStart(wholeDocRange.endContainer, wholeDocRange.endOffset);
|
|
||||||
endPt.setEnd(wholeDocRange.endContainer, wholeDocRange.endOffset);
|
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:
|
// Find and replace from here to end of document:
|
||||||
var foundRange;
|
var foundRange;
|
||||||
|
@ -267,25 +272,40 @@ function onReplaceAll()
|
||||||
selecRange = selection.getRangeAt(0);
|
selecRange = selection.getRangeAt(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If wrapping, find from start of document back to start point.
|
// If no wrapping, then we're done
|
||||||
selecRange.setStart(wholeDocRange.startContainer, wholeDocRange.startOffset);
|
if (!gReplaceDialog.wrap.checked)
|
||||||
selecRange.setEnd(wholeDocRange.startContainer, wholeDocRange.startOffset);
|
return;
|
||||||
// Collapse origRange to start:
|
|
||||||
origRange.setEnd(origRange.startContainer, origRange.startOffset);
|
// If wrapping, find from start/end of document back to start point.
|
||||||
if (gReplaceDialog.wrap.checked)
|
if (gReplaceDialog.searchBackwards.checked)
|
||||||
{
|
{
|
||||||
while ((foundRange = finder.Find(findStr, wholeDocRange,
|
// Collapse origRange to end
|
||||||
selecRange, origRange)) != null)
|
origRange.setStart(origRange.endContainer, origRange.endOffset);
|
||||||
{
|
// Set current position to document end
|
||||||
gEditor.selection.removeAllRanges();
|
selecRange.setEnd(wholeDocRange.endContainer, wholeDocRange.endOffset);
|
||||||
gEditor.selection.addRange(foundRange);
|
selecRange.setStart(wholeDocRange.endContainer, wholeDocRange.endOffset);
|
||||||
gEditor.insertText(repStr);
|
}
|
||||||
selection = gEditor.selection;
|
else
|
||||||
if (selection.rangeCount <= 0) {
|
{
|
||||||
return;
|
// Collapse origRange to start
|
||||||
}
|
origRange.setEnd(origRange.startContainer, origRange.startOffset);
|
||||||
selecRange = selection.getRangeAt(0);
|
// 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче