diff --git a/platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsImpl.kt b/platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsImpl.kt index 856acd5a14f4..5517a5786735 100644 --- a/platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsImpl.kt +++ b/platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsImpl.kt @@ -91,7 +91,7 @@ private const val LAYOUT_DONE: @NonNls String = "Layout.done" @DirtyUI open class JBTabsImpl( private var project: Project?, - parentDisposable: Disposable, + private val parentDisposable: Disposable, ) : JComponent(), JBTabsEx, PropertyChangeListener, TimerListener, DataProvider, PopupMenuListener, JBTabsPresentation, Queryable, UISettingsListener, QuickActionProvider, MorePopupAware, Accessible { @@ -154,7 +154,8 @@ open class JBTabsImpl( } } - private final val RELAYOUT_DELAY = 5000 + private val RELAYOUT_DELAY = 2000 + private val relayoutAlarm = Alarm(parentDisposable) private val visibleInfos = ArrayList() private val infoToPage = HashMap() @@ -208,6 +209,8 @@ open class JBTabsImpl( private var hideTabs = false private var isRequestFocusOnLastFocusedComponent = false private var listenerAdded = false + var isRecentlyActive: Boolean = false + private set @JvmField internal val attractions: MutableSet = HashSet() @@ -395,11 +398,21 @@ open class JBTabsImpl( scrollBarChangeListener = ChangeListener { updateTabsOffsetFromScrollBar() } } + private fun setRecentlyActive() { + relayoutAlarm.cancelAllRequests() + isRecentlyActive = true + relayoutAlarm.addRequest({ + isRecentlyActive = false + relayout(false, false) + }, RELAYOUT_DELAY) + + } + fun isScrollBarAdjusting(): Boolean = scrollBar.valueIsAdjusting private fun addMouseMotionAwtListener(parentDisposable: Disposable) { StartupUiUtil.addAwtListener(object : AWTEventListener { - val afterScroll = Alarm(parentDisposable) + override fun eventDispatched(event: AWTEvent) { val tabRectangle = lastLayoutPass?.headerRectangle ?: return @@ -417,13 +430,9 @@ open class JBTabsImpl( } isMouseInsideTabsArea = inside - afterScroll.cancelAllRequests() + relayoutAlarm.cancelAllRequests() if (!inside) { - afterScroll.addRequest({ - if (!isMouseInsideTabsArea) { - relayout(false, false) - } - }, RELAYOUT_DELAY) + setRecentlyActive() } } }, AWTEvent.MOUSE_MOTION_EVENT_MASK, parentDisposable) @@ -543,10 +552,8 @@ open class JBTabsImpl( fun unHover(label: TabLabel) { if (tabLabelAtMouse === label) { tabLabelAtMouse = null - Alarm().addRequest({ - label.revalidate() - label.repaint() - }, RELAYOUT_DELAY) + label.revalidate() + label.repaint() } } @@ -1841,6 +1848,7 @@ open class JBTabsImpl( } private fun updateTabsOffsetFromScrollBar() { + if (!isScrollBarAdjusting()) setRecentlyActive() val currentUnitsOffset = effectiveLayout!!.scrollOffset val updatedOffset = scrollBarModel.value effectiveLayout!!.scroll(updatedOffset - currentUnitsOffset) diff --git a/platform/platform-api/src/com/intellij/ui/tabs/impl/multiRow/ScrollableMultiRowLayout.kt b/platform/platform-api/src/com/intellij/ui/tabs/impl/multiRow/ScrollableMultiRowLayout.kt index 2c099c6fda95..e7df568c1087 100644 --- a/platform/platform-api/src/com/intellij/ui/tabs/impl/multiRow/ScrollableMultiRowLayout.kt +++ b/platform/platform-api/src/com/intellij/ui/tabs/impl/multiRow/ScrollableMultiRowLayout.kt @@ -11,7 +11,7 @@ class ScrollableMultiRowLayout(tabs: JBTabsImpl, private var scrollOffset: Int = 0 override fun layoutTable(visibleInfos: List): LayoutPassInfo { - if (!tabs.isMouseInsideTabsArea && !tabs.isHideTabs && !tabs.isScrollBarAdjusting()) { + if (!tabs.isMouseInsideTabsArea && !tabs.isHideTabs && !tabs.isScrollBarAdjusting() && !tabs.isRecentlyActive) { scrollToSelectedTab() } return super.layoutTable(visibleInfos) diff --git a/platform/platform-api/src/com/intellij/ui/tabs/impl/singleRow/ScrollableSingleRowLayout.java b/platform/platform-api/src/com/intellij/ui/tabs/impl/singleRow/ScrollableSingleRowLayout.java index 7309d9c241bb..e05241f034cc 100644 --- a/platform/platform-api/src/com/intellij/ui/tabs/impl/singleRow/ScrollableSingleRowLayout.java +++ b/platform/platform-api/src/com/intellij/ui/tabs/impl/singleRow/ScrollableSingleRowLayout.java @@ -62,7 +62,7 @@ public final class ScrollableSingleRowLayout extends SingleRowLayout { } private void doScrollToSelectedTab(SingleRowPassInfo passInfo) { - if (myTabs.isMouseInsideTabsArea() || myTabs.isScrollBarAdjusting()) { + if (myTabs.isMouseInsideTabsArea() || myTabs.isScrollBarAdjusting() || myTabs.isRecentlyActive()) { return; } int offset = -myScrollOffset;