}
}
ITextFileBufferManager bm = FileBuffers.getTextFileBufferManager();
try {
bm.connect(file.getFullPath(), new SubProgressMonitor(pm, 1));
ITextFileBuffer fb = bm.getTextFileBuffer(file.getFullPath());
boolean wasDirty = fb.isDirty();
IDocument doc = fb.getDocument();
for (int i = 0; i < markers.length; i++) {
PositionTracker tracker = InternalSearchUI.getInstance().getPositionTracker();
Match match = markers[i];
int offset = match.getOffset();
int length = match.getLength();
Position currentPosition = tracker.getCurrentPosition(match);
if (currentPosition != null) {
offset = currentPosition.offset;
length = currentPosition.length;
}
String originalText = doc.get(offset, length);
String replacementString = computeReplacementString(pattern, originalText, replacementText);
doc.replace(offset, length, replacementString);
fMarkers.remove(match);
fPage.getInput().removeMatch(match);
}
if (!wasDirty) {
fb.commit(new SubProgressMonitor(pm, 1), true);
fSaved = true;
}
} finally {
bm.disconnect(file.getFullPath(), new SubProgressMonitor(pm, 1));
}