void () { String text = """ import java.awt.List; [import java.util.ArrayList; ]import java.util.HashMap; import java.util.Map;"""; RangeMarker marker = createMarker(text); WriteAction.run(() -> { synchronizer.startTransaction(getProject(), document, psiFile); String newText = StringUtil.replaceSubstring(document.getText(), marker.getTextRange(), ""); synchronizer.replaceString(document, 0, document.getTextLength(), newText); final List<DocumentEvent> events = new ArrayList<>(); document.addDocumentListener(new DocumentListener() { @Override public void documentChanged(@NotNull DocumentEvent e) { events.add(e); } }); synchronizer.commitTransaction(document); assertEquals(newText, document.getText()); DocumentEvent event = assertOneElement(events); assertEquals("DocumentEventImpl[myOffset=22, myOldLength=28, myNewLength=0].", event.toString()); }); }