From 5b0200db5cb75d2437f1df61e6fcdadef5d0399a Mon Sep 17 00:00:00 2001 From: "Vassiliy.Kudryashov" Date: Mon, 29 Nov 2021 21:09:25 +0300 Subject: [PATCH] IDEA-278414 A tool in View Mode Window is instantly getting closed GitOrigin-RevId: dab7589ea5bd812d4f4dc6a1db2090f339582bed --- .../platform-impl/src/com/intellij/openapi/ui/FrameWrapper.kt | 2 +- .../src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/FrameWrapper.kt b/platform/platform-impl/src/com/intellij/openapi/ui/FrameWrapper.kt index dc1c5194c102..b51aea587284 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/FrameWrapper.kt +++ b/platform/platform-impl/src/com/intellij/openapi/ui/FrameWrapper.kt @@ -113,7 +113,7 @@ open class FrameWrapper @JvmOverloads constructor(project: Project?, val focusListener = object : WindowAdapter() { override fun windowOpened(e: WindowEvent) { val focusManager = IdeFocusManager.getInstance(project) - val toFocus = preferredFocusedComponent ?: focusManager.getFocusTargetFor(component!!) + val toFocus = focusManager.getLastFocusedFor(e.window) ?: preferredFocusedComponent ?: focusManager.getFocusTargetFor(component!!) if (toFocus != null) { focusManager.requestFocus(toFocus, true) } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.kt b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.kt index 21fc3717de9b..04cfbb00e955 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.kt +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.kt @@ -2289,7 +2289,7 @@ enum class ToolWindowProperty { private fun isInActiveToolWindow(component: Any?, activeToolWindow: ToolWindowImpl): Boolean { var source = if (component is JComponent) component else null - val activeToolWindowComponent = activeToolWindow.getComponentIfInitialized() + val activeToolWindowComponent = activeToolWindow.decoratorComponent if (activeToolWindowComponent != null) { while (source != null && source !== activeToolWindowComponent) { source = ComponentUtil.getClientProperty(source, ToolWindowManagerImpl.PARENT_COMPONENT) ?: source.parent as? JComponent