diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorManagerImpl.kt b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorManagerImpl.kt index fd94b5c0713f..5662b1220c88 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorManagerImpl.kt +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorManagerImpl.kt @@ -921,6 +921,15 @@ open class FileEditorManagerImpl( } override suspend fun openFile(file: VirtualFile, options: FileEditorOpenOptions): FileEditorComposite { + if (!ClientId.isCurrentlyUnderLocalId) { + return clientFileEditorManager?.openFileAsync( + file = file, + // it used to be passed as forceCreate=false there, so we need to pass it as reuseOpen=true + // otherwise, any navigation will open a new editor composite which is invisible in RD mode + options = options.copy(reuseOpen = true), + ) ?: FileEditorComposite.EMPTY + } + val mode = options.openMode if (mode == OpenMode.NEW_WINDOW) { return withContext(Dispatchers.EDT) { @@ -951,19 +960,13 @@ open class FileEditorManagerImpl( } } - val isCurrentlyUnderLocalId = ClientId.isCurrentlyUnderLocalId - - var composite: FileEditorComposite? = withContext(Dispatchers.EDT) { + val composite: FileEditorComposite? = withContext(Dispatchers.EDT) { writeIntentReadAction { val window = getWindowToOpen(options, file) if (forbidSplitFor(file) && !window.isFileOpen(file)) { closeFile(file) } - if (!isCurrentlyUnderLocalId) { - return@writeIntentReadAction null - } - @Suppress("DuplicatedCode") runBulkTabChangeInEdt(window.owner) { doOpenInEdt(window = window, file = file, options = options, fileEntry = null) @@ -971,21 +974,11 @@ open class FileEditorManagerImpl( } } - if (composite == null) { - assert(!isCurrentlyUnderLocalId) - composite = clientFileEditorManager?.openFileAsync( - file = file, - // it used to be passed as forceCreate=false there, so we need to pass it as reuseOpen=true - // otherwise, any navigation will open a new editor composite which is invisible in RD mode - options = options.copy(reuseOpen = true), - ) ?: FileEditorComposite.EMPTY - } - // The client of the `openFile` API expects an editor to be available after invocation, so we wait until the file is opened if (composite is EditorComposite) { composite.waitForAvailable() } - return composite + return composite ?: FileEditorComposite.EMPTY } @ApiStatus.Internal