void () { PsiJavaFile file = (PsiJavaFile)myFixture.configureByText("Foo.java", """ public class Foo { } class Bar {} """); VirtualFile virtualFile = file.getVirtualFile(); assertNotNull(virtualFile); FileEditorManagerEx manager = FileEditorManagerEx.getInstanceEx(getProject()); manager.openFile(virtualFile, true); assertEquals(0, getOffset(virtualFile)); manager.closeAllFiles(); PsiClass psiClass = file.getClasses()[1]; int identifierOffset = psiClass.getNameIdentifier().getTextOffset(); NavigationUtil.activateFileWithPsiElement(psiClass); assertEquals(identifierOffset, getOffset(virtualFile)); getEditor(virtualFile).getCaretModel().moveToOffset(identifierOffset + 3); // it's still inside the class, so keep it assertEquals(identifierOffset + 3, getOffset(virtualFile)); manager.closeAllFiles(); assertThat(manager.getSelectedEditor()).isNull(); NavigationUtil.activateFileWithPsiElement(psiClass); assertEquals(identifierOffset + 3, getOffset(virtualFile)); getEditor(virtualFile).getCaretModel().moveToOffset(0); NavigationUtil.activateFileWithPsiElement(psiClass); assertEquals(identifierOffset, getOffset(virtualFile)); manager.closeAllFiles(); NavigationUtil.activateFileWithPsiElement(file); // GoTo file should keep offset assertEquals(identifierOffset, getOffset(virtualFile)); }