Editor (@NonNls @NotNull String fileText) { return WriteCommandAction.writeCommandAction(getProject()).compute(() -> { Document fakeDocument = EditorFactory.getInstance().createDocument(fileText); EditorTestUtil.CaretAndSelectionState caretsState = EditorTestUtil.extractCaretAndSelectionMarkers(fakeDocument); String newFileText = fakeDocument.getText(); Document document = EditorFactory.getInstance().createDocument(newFileText); Editor editor = EditorFactory.getInstance().createEditor(document, getProject()); ((EditorImpl)editor).setCaretActive(); EditorTestUtil.setCaretsAndSelection(editor, caretsState); getIndexingMode().ensureIndexingStatus(getProject()); return editor; }); }