void (EditorEx editor, Random random) { Document document = editor.getDocument(); int textLength = document.getTextLength(); if (textLength <= 0) return; int count = 1 + random.nextInt(Math.min(MAX_CHARS_TO_REMOVE, textLength)); int offset = random.nextInt(textLength - count + 1); WriteCommandAction.writeCommandAction(getProject()).run(() -> document.deleteString(offset, offset + count)); }