void (TemplateImpl template) { int firstUnchangedVar = maxEditedVariable.get() + 1; if (firstUnchangedVar >= template.getVariableCount()) return; TextRange startRange = templateState.getVariableRange(template.getVariableNameAt(firstUnchangedVar)); TextRange endRange = templateState.getVariableRange(template.getVariableNameAt(template.getVariableCount() - 1)); if (startRange == null || endRange == null) return; WriteCommandAction.runWriteCommandAction(editor.getProject(), () -> editor.getDocument().deleteString(startRange.getStartOffset(), endRange.getEndOffset())); }