void (int startOffset, int endOffset, @NotNull CharSequence s) { Collection<StringOperation> operations = prepareReplaceString(startOffset, endOffset, s); int delta = 0; for (StringOperation stringOperation : operations) { TextRange hostRange = stringOperation.getRange(); CharSequence replace = stringOperation.getReplacement(); myDelegate.replaceString(hostRange.getStartOffset() + delta, hostRange.getEndOffset() + delta, replace); delta -= hostRange.getLength() - replace.length(); } }