[vcs-log] look up log tabs for commit jump manually instead of the cache

GitOrigin-RevId: ab290ba7b8678e08fe46156ef9013b14868503c4
This commit is contained in:
Ivan Semenov
2025-05-16 23:39:43 +02:00
committed by intellij-monorepo-bot
parent dc34b92226
commit c47ce54c13
5 changed files with 60 additions and 31 deletions

View File

@@ -2873,7 +2873,6 @@ f:com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager
- sf:getInstance(com.intellij.openapi.project.Project):com.intellij.openapi.vcs.changes.ui.ChangesViewContentI
- sf:getToolWindowFor(com.intellij.openapi.project.Project,java.lang.String):com.intellij.openapi.wm.ToolWindow
- sf:getToolWindowIdFor(com.intellij.openapi.project.Project,java.lang.String):java.lang.String
- f:initLazyContent(com.intellij.ui.content.Content):V
- sf:isCommitToolWindowShown(com.intellij.openapi.project.Project):Z
- f:isContentSelected(java.lang.String):Z
- sf:isToolWindowTabVertical(com.intellij.openapi.project.Project,java.lang.String):Z

View File

@@ -26,6 +26,7 @@ import com.intellij.util.messages.MessageBusConnection
import com.intellij.vcs.commit.CommitMode
import com.intellij.vcs.commit.CommitModeManager
import kotlinx.coroutines.CoroutineScope
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.annotations.NonNls
import java.util.function.Predicate
@@ -208,13 +209,6 @@ class ChangesViewContentManager private constructor(private val project: Project
return content.resolveToolWindowId()
}
fun initLazyContent(content: Content) {
val provider = content.getUserData(CONTENT_PROVIDER_SUPPLIER_KEY)?.invoke() ?: return
content.putUserData(CONTENT_PROVIDER_SUPPLIER_KEY, null)
provider.initTabContent(content)
IJSwingUtilities.updateComponentTreeUI(content.component)
}
private inner class ContentProvidersListener(val toolWindow: ToolWindow) : ContentManagerListener, ToolWindowManagerListener {
override fun stateChanged(toolWindowManager: ToolWindowManager) {
if (toolWindow.isVisible) {
@@ -325,6 +319,14 @@ class ChangesViewContentManager private constructor(private val project: Project
return !isContentVertical || !isCommitToolWindowShown(project)
}
@ApiStatus.Internal
fun initLazyContent(content: Content) {
val provider = content.getUserData(CONTENT_PROVIDER_SUPPLIER_KEY)?.invoke() ?: return
content.putUserData(CONTENT_PROVIDER_SUPPLIER_KEY, null)
provider.initTabContent(content)
IJSwingUtilities.updateComponentTreeUI(content.component)
}
/**
* Specified tab order in the toolwindow.
*

View File

@@ -8,10 +8,7 @@ import com.intellij.openapi.vcs.VcsNotifier
import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager
import com.intellij.openapi.wm.ToolWindow
import com.intellij.openapi.wm.ToolWindowManager
import com.intellij.ui.content.Content
import com.intellij.ui.content.ContentManager
import com.intellij.ui.content.TabDescriptor
import com.intellij.ui.content.TabGroupId
import com.intellij.ui.content.*
import com.intellij.util.Consumer
import com.intellij.util.ContentUtilEx
import com.intellij.util.concurrency.annotations.RequiresEdt
@@ -40,6 +37,40 @@ object VcsLogContentUtil {
return uis.singleOrNull()
}
private fun componentsSequence(toolWindow: ToolWindow): Sequence<JComponent> {
val contentManager = toolWindow.contentManagerIfCreated ?: return emptySequence()
return sequence {
for (content in contentManager.getContents()) {
if (content is TabbedContent) {
content.tabs.forEach { pair ->
pair.second?.let { yield(it) }
}
}
else {
yield(content.component)
}
}
}
}
internal fun <U : VcsLogUi> findLogUi(toolWindow: ToolWindow, clazz: Class<U>, select: Boolean, condition: (U) -> Boolean): U? {
componentsSequence(toolWindow).forEach {
val logUi = getLogUi(it)
if (logUi != null && clazz.isInstance(logUi)) {
@Suppress("UNCHECKED_CAST")
logUi as U
if (condition(logUi)) {
if (select) {
ContentUtilEx.selectContent(toolWindow.contentManager, it, true)
}
return logUi
}
}
}
return null
}
internal fun selectLogUi(project: Project, logUi: VcsLogUi, requestFocus: Boolean = true): Boolean {
val toolWindow = getToolWindow(project) ?: return false
val manager = toolWindow.contentManager

View File

@@ -240,11 +240,6 @@ open class VcsLogManager @Internal constructor(
return managedUis.values.filter { uiLocations[it.id] == location }
}
@Internal
fun getVisibleLogUis(location: VcsLogTabLocation): List<VcsLogUi> {
return managedUis.values.filter { uiLocations[it.id] == location && it.isVisible() }
}
@Internal
fun getLogUiInformation(): String =
managedUis.values.joinToString("\n") { ui ->

View File

@@ -146,15 +146,19 @@ internal class VcsProjectLogManager(
}
}
val selectedUis = getVisibleLogUis(VcsLogTabLocation.TOOL_WINDOW).filterIsInstance<MainVcsLogUi>()
selectedUis.find { ui -> predicate(ui) && ui.showCommitSync(hash, root, requestFocus) }?.let { return it }
val selectedUi = VcsLogContentUtil.findSelectedLogUi(window) as? MainVcsLogUi
if (selectedUi != null && predicate(selectedUi)) {
if (selectedUi.showCommitSync(hash, root, requestFocus)) {
return selectedUi
}
}
val mainLogContent = VcsLogContentUtil.findMainLog(window.contentManager)
if (mainLogContent != null) {
ChangesViewContentManager.getInstanceImpl(project)?.initLazyContent(mainLogContent)
if (selectedUi?.id != MAIN_LOG_ID) {
val mainLogContent = VcsLogContentUtil.findMainLog(window.contentManager)
if (mainLogContent != null) {
ChangesViewContentManager.initLazyContent(mainLogContent)
val mainLogUi = awaitMainUi()
if (!selectedUis.contains(mainLogUi)) {
val mainLogUi = awaitMainUi()
mainLogUi.refresher.setValid(true, false) // since the main ui is not visible, it needs to be validated to find the commit
if (predicate(mainLogUi) && mainLogUi.showCommitSync(hash, root, requestFocus)) {
window.contentManager.setSelectedContent(mainLogContent)
@@ -163,14 +167,12 @@ internal class VcsProjectLogManager(
}
}
val otherUis = getLogUis(VcsLogTabLocation.TOOL_WINDOW).filterIsInstance<MainVcsLogUi>() - selectedUis.toSet()
otherUis.find { ui ->
ui.refresher.setValid(true, false)
predicate(ui) && ui.showCommitSync(hash, root, requestFocus)
}?.let { ui ->
VcsLogContentUtil.selectLogUi(project, ui, requestFocus)
return ui
val existingUi = VcsLogContentUtil.findLogUi(window, MainVcsLogUi::class.java, true) {
if (it === selectedUi && it === mainUi) return@findLogUi false
it.refresher.setValid(true, false)
predicate(it) && it.showCommitSync(hash, root, requestFocus)
}
if (existingUi != null) return existingUi
val newUi = openNewLogTab(VcsLogTabLocation.TOOL_WINDOW, VcsLogFilterObject.EMPTY_COLLECTION)
if (newUi.showCommit(hash, root, requestFocus)) return newUi