boolean (VariableInplaceRenameHandler handler, final String newName, @NotNull Editor editor, @NotNull PsiElement elementAtCaret) { Project project = editor.getProject(); Disposable disposable = Disposer.newDisposable(); try { TemplateManagerImpl.setTemplateTesting(disposable); DataContext context = DataManager.getInstance().getDataContext(editor.getComponent()); InplaceRefactoring renamer = handler.doRename(Objects.requireNonNullElse(PsiElementRenameHandler.getElement(context), elementAtCaret), editor, context); if (editor instanceof EditorWindow) { editor = ((EditorWindow)editor).getDelegate(); } TemplateState state = TemplateManagerImpl.getTemplateState(editor); if (state == null) { if (renamer != null) { renamer.finish(false); } return false; } final TextRange range = state.getCurrentVariableRange(); assert range != null; final Editor finalEditor = editor; WriteCommandAction.writeCommandAction(project) .run(() -> finalEditor.getDocument().replaceString(range.getStartOffset(), range.getEndOffset(), newName)); state = TemplateManagerImpl.getTemplateState(editor); assert state != null; state.gotoEnd(false); } finally { Disposer.dispose(disposable); } return true; }