void (AntDomTargetReference ref, String newText) { Integer lengthDelta = null; for (AntDomTargetReference r : myRefs) { if (lengthDelta != null) { r.setRangeInElement(r.getRangeInElement().shiftRight(lengthDelta)); } else if (r.equals(ref)) { final TextRange range = r.getRangeInElement(); final int oldLength = range.getLength(); lengthDelta = Integer.valueOf(newText.length() - oldLength); r.setRangeInElement(range.grown(lengthDelta)); } } }