String (final @NotNull TextRange textRange, final @NotNull EditorEx editor, boolean erase, final boolean preserveMarkup) { ThreadingAssertions.assertEventDispatchThread(); String result = addTextRangeToHistory(textRange, editor, preserveMarkup); if (erase) { DocumentUtil.writeInRunUndoTransparentAction( () -> editor.getDocument().deleteString(textRange.getStartOffset(), textRange.getEndOffset())); } // always scroll to end on user input scrollToEnd(); return result; }