[ui] IJPL-161939 IJPL-191798 do not fail to close editor tab if an invalid focus target was specified

Fix broken toString after 08463bfc5a4e46a27bcec10d9b5ff9bfadf898e1

GitOrigin-RevId: abb44a585d5776fa5fbec4ff4edf8ba16c4bde11
This commit is contained in:
Aleksey Pivovarov
2026-01-05 17:32:49 +00:00
committed by intellij-monorepo-bot
parent 14bdfb7483
commit 0b021032a9
3 changed files with 12 additions and 5 deletions
@@ -297,7 +297,7 @@ class TabInfo(var component: JComponent) : Queryable, PlaceProvider {
changeSupport.firePropertyChange(ALERT_STATUS, null, false)
}
override fun toString(): String = LoadingNode.getText()
override fun toString(): String = text
fun getAlertIcon(): AlertIcon = alertIcon ?: DEFAULT_ALERT_ICON
@@ -2464,10 +2464,13 @@ open class JBTabsImpl internal constructor(
val toSelect = if (forcedSelectionTransfer == null) {
getToSelectOnRemoveOf(info!!)
}
else {
assert(visibleInfos.contains(forcedSelectionTransfer)) { "Cannot find tab for selection transfer, tab=$forcedSelectionTransfer" }
else if (visibleInfos.contains(forcedSelectionTransfer)) {
forcedSelectionTransfer
}
else {
LOG.error("Cannot find tab for selection transfer, tab=$forcedSelectionTransfer")
getToSelectOnRemoveOf(info!!)
}
val result = ActionCallback()
if (toSelect == null) {
@@ -730,8 +730,12 @@ class EditorWindow internal constructor(
fileBeingClosed: VirtualFile,
componentIndex: Int,
): TabInfo? {
tabBeingClosed.previousSelection?.let {
return it
val previousSelection = tabBeingClosed.previousSelection
if (previousSelection != null) {
// the WeakReference might reference an already closed tab
if (tabbedPane.editorTabs.getVisibleInfos().contains(previousSelection)) {
return previousSelection
}
}
val indexToSelect = computeIndexToSelect(fileBeingClosed = fileBeingClosed, fileIndex = componentIndex)