From 8f4f827aac74706e13e331a7faf4afc28a0dab47 Mon Sep 17 00:00:00 2001 From: Mikhail Sokolov Date: Thu, 17 Oct 2024 14:37:04 +0200 Subject: [PATCH] IJPL-162911 Search Everywhere: file paths and library names overlap in search results for some PNG files GitOrigin-RevId: e36dd03565336df5527246b0e2cc3c5fee60bc01 --- .../PsiElementBackgroundListCellRenderer.kt | 36 ++++++++++++------- .../PsiElementListCellRendererComponent.java | 6 ++-- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/util/PsiElementBackgroundListCellRenderer.kt b/platform/lang-impl/src/com/intellij/ide/util/PsiElementBackgroundListCellRenderer.kt index 89e9c85b49f6..e1bab7bc225f 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/PsiElementBackgroundListCellRenderer.kt +++ b/platform/lang-impl/src/com/intellij/ide/util/PsiElementBackgroundListCellRenderer.kt @@ -17,8 +17,8 @@ import com.intellij.util.ui.JBUI import com.intellij.util.ui.NamedColorUtil import com.intellij.util.ui.UIUtil import kotlinx.coroutines.Deferred -import java.awt.BorderLayout import java.awt.Component +import java.awt.Dimension import javax.swing.* internal class PsiElementBackgroundListCellRenderer( @@ -68,13 +68,12 @@ internal class PsiElementBackgroundListCellRenderer( myComponent.selectionColor = bg - val locationText = presentation.locationText - if (locationText != null) { - val spacer = JPanel() - spacer.isOpaque = false - spacer.border = BorderFactory.createEmptyBorder(0, 2, 0, 2) - myComponent.add(spacer, BorderLayout.CENTER) + val spacer = JPanel().apply { + isOpaque = false + border = BorderFactory.createEmptyBorder(0, 2, 0, 2) + } + val rightComponent = presentation.locationText?.let { val rightRenderer: ListCellRenderer = object : DefaultListCellRenderer() { override fun getListCellRendererComponent(list: JList<*>, value: Any?, @@ -85,17 +84,24 @@ internal class PsiElementBackgroundListCellRenderer( foreground = if (isSelected) NamedColorUtil.getListSelectionForeground(cellHasFocus) else NamedColorUtil.getInactiveTextColor() isOpaque = false icon = presentation.locationIcon - text = locationText + text = it if (!usedInPopup || !ExperimentalUI.isNewUI()) { border = BorderFactory.createEmptyBorder(0, 0, 0, UIUtil.getListCellHPadding()) } horizontalTextPosition = LEFT horizontalAlignment = RIGHT + + var minWidth = 0 + minWidth += insets.left + insets.right + minWidth += icon.iconWidth + minWidth += iconTextGap + minWidth += getFontMetrics(font).stringWidth("...") + minimumSize = JBUI.size(minWidth, minimumSize.height) + return component } } - val rightRendererComponent = rightRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus) - myComponent.add(rightRendererComponent, BorderLayout.EAST) + rightRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus) } val leftRenderer: ListCellRenderer = object : ColoredListCellRenderer() { @@ -120,6 +126,8 @@ internal class PsiElementBackgroundListCellRenderer( presentation.presentableText, this, nameAttributes, itemMatchers.nameMatcher, bg, selected ) + minimumSize = Dimension(preferredSize.width, minimumSize.height) + val containerText = presentation.containerText if (containerText != null) { val containerTextAttributes = presentation.containerTextAttributes?.let { @@ -134,8 +142,12 @@ internal class PsiElementBackgroundListCellRenderer( } } - val leftRendererComponent = leftRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus) - myComponent.add(leftRendererComponent, BorderLayout.WEST) + val leftComponent = leftRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus) + myComponent.add(leftComponent) + rightComponent?.let { + myComponent.add(spacer) + myComponent.add(it) + } return myComponent } diff --git a/platform/lang-impl/src/com/intellij/ide/util/PsiElementListCellRendererComponent.java b/platform/lang-impl/src/com/intellij/ide/util/PsiElementListCellRendererComponent.java index 9c9561b4076f..d016b225fcc4 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/PsiElementListCellRendererComponent.java +++ b/platform/lang-impl/src/com/intellij/ide/util/PsiElementListCellRendererComponent.java @@ -11,15 +11,13 @@ import java.awt.*; final class PsiElementListCellRendererComponent extends SelectablePanel { PsiElementListCellRendererComponent() { - setLayout(new BorderLayout()); + setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); } private final class MyAccessibleContext extends JPanel.AccessibleJPanel { @Override public String getAccessibleName() { - LayoutManager lm = getLayout(); - assert lm instanceof BorderLayout; - Component leftCellRendererComp = ((BorderLayout)lm).getLayoutComponent(BorderLayout.WEST); + Component leftCellRendererComp = getComponent(0); return leftCellRendererComp instanceof Accessible ? leftCellRendererComp.getAccessibleContext().getAccessibleName() : super.getAccessibleName(); }