Editor (@NotNull PsiElement elementAtCaret) { // sometimes the element found by TargetElementUtil may belong to the other editor, e.g, in case of an injected element // but inplace rename requires that both element and the editor must be consistent Editor editorForElement = PsiEditorUtil.getInstance().findEditorByPsiElement(elementAtCaret); if (editorForElement == null) { PsiFile containingFile = elementAtCaret.getContainingFile(); VirtualFile virtualFile = containingFile.getVirtualFile(); Project project = containingFile.getProject(); editorForElement = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, virtualFile), false); editorForElement.getCaretModel().moveToOffset(elementAtCaret.getTextOffset()); } return editorForElement; }