From 5bbb4bfbe0f119dcade24257d4963d2396d7bef8 Mon Sep 17 00:00:00 2001 From: Egor Ushakov Date: Fri, 9 May 2025 19:13:25 +0200 Subject: [PATCH] IDEA-312437 PinToTopManager hodls Java psi GitOrigin-RevId: 25c8cd9a790277e587f71f750a3d0e4dee0ae4ae --- .../impl/pinned/items/XDebuggerPinToTopManager.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/pinned/items/XDebuggerPinToTopManager.kt b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/pinned/items/XDebuggerPinToTopManager.kt index 5812a6164654..e232decc144e 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/pinned/items/XDebuggerPinToTopManager.kt +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/pinned/items/XDebuggerPinToTopManager.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.xdebugger.impl.pinned.items import com.intellij.openapi.Disposable @@ -15,6 +15,7 @@ import com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl import icons.PlatformDebuggerImplIcons import kotlinx.coroutines.CoroutineScope import org.jetbrains.annotations.ApiStatus.Internal +import java.lang.ref.WeakReference @Internal class XDebuggerPinToTopManager(coroutineScope: CoroutineScope) { @@ -29,7 +30,7 @@ class XDebuggerPinToTopManager(coroutineScope: CoroutineScope) { private val listeners = mutableListOf() private var nodeHoverLifetime: Disposable? = null - private var activeNode: XDebuggerTreeNode? = null + private var activeNode: WeakReference? = null private var pinnedMembers = HashSet() private val pinToTopIconAlarm = Alarm(threadToUse = Alarm.ThreadToUse.SWING_THREAD, coroutineScope = coroutineScope) @@ -39,7 +40,7 @@ class XDebuggerPinToTopManager(coroutineScope: CoroutineScope) { fun isEnabled(): Boolean = Registry.`is`("debugger.field.pin.to.top", true) fun onNodeHovered(node: XDebuggerTreeNode?, lifetimeHolder: Disposable) { - if (activeNode == node) { + if (activeNode?.get() == node) { return } if (!isEnabled()) { @@ -58,8 +59,10 @@ class XDebuggerPinToTopManager(coroutineScope: CoroutineScope) { } var oldIcon = valueNode.icon + val nodeRef = WeakReference(node) val changeIconLifetime = Disposable { + val node = nodeRef.get() ?: return@Disposable val xValuePresentation = node.valuePresentation if (node.icon == PlatformDebuggerImplIcons.PinToTop.UnpinnedItem && xValuePresentation != null) { node.setPresentation(oldIcon, xValuePresentation, !node.isLeaf) @@ -67,7 +70,7 @@ class XDebuggerPinToTopManager(coroutineScope: CoroutineScope) { activeNode = null nodeHoverLifetime = null } - activeNode = node + activeNode = nodeRef nodeHoverLifetime = changeIconLifetime pinToTopIconAlarm.addRequest(