TemplateState (@NotNull Editor editor) { Editor topLevelEditor = InjectedLanguageEditorUtil.getTopLevelEditor(editor); TemplateState prevState = clearTemplateState(topLevelEditor); if (prevState != null) Disposer.dispose(prevState); TemplateStateProcessor processor = editor instanceof IntentionPreviewEditor ? new NonInteractiveTemplateStateProcessor() : new InteractiveTemplateStateProcessor(); TemplateState state = new TemplateState(myProject, topLevelEditor, topLevelEditor.getDocument(), processor); Disposer.register(this, state); TemplateManagerUtilBase.setTemplateState(topLevelEditor, state); return state; }