void () { FileEditorManagerListener fileEditorListener = new FileEditorManagerListener() { @Override public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) { if (!Comparing.equal(file, getVirtualFile())) { return; } Editor selectedTextEditor = source.getSelectedTextEditor(); for (FileEditor fileEditor : source.getAllEditors(file)) { if (!(fileEditor instanceof TextEditor)) { continue; } final EditorEx editor = (EditorEx)((TextEditor)fileEditor).getEditor(); editor.addFocusListener(myFocusListener); if (selectedTextEditor == editor) { // already focused myCurrentEditor = editor; } ActionUtil.copyRegisteredShortcuts(editor.getComponent(), myConsoleEditor.getComponent()); } } @Override public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) { if (!Comparing.equal(file, getVirtualFile())) { return; } if (!Boolean.TRUE.equals(file.getUserData(FileEditorManagerImpl.CLOSING_TO_REOPEN))) { if (myCurrentEditor != null && myCurrentEditor.isDisposed()) { myCurrentEditor = null; } } } }; myBusConnection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, fileEditorListener); FileEditorManager editorManager = FileEditorManager.getInstance(getProject()); if (editorManager.isFileOpen(getVirtualFile())) { fileEditorListener.fileOpened(editorManager, getVirtualFile()); } }