void (@NotNull TemplateState state, Template template) { final TextResult value = state.getVariableValue(varName); myNewType = value != null ? value.getText() : ""; final int segmentsCount = state.getSegmentsCount(); final Document document = state.getEditor().getDocument(); ApplicationManager.getApplication().runWriteAction(() -> { for (int i = 0; i < segmentsCount; i++) { final TextRange segmentRange = state.getSegmentRange(i); document.replaceString(segmentRange.getStartOffset(), segmentRange.getEndOffset(), oldTypeText); } }); }