From b4967bd2ed6074f57e59c4ec74dd791dd3f305b8 Mon Sep 17 00:00:00 2001 From: Pavel Porvatov Date: Wed, 16 Jul 2025 16:47:30 +0200 Subject: [PATCH] IJPL-197361 Multi-selection is not repainted while focus changing GitOrigin-RevId: 2f2ec413f1e34644a5c43d86b0309d670f2adf1b --- .../ui/components/WideSelectionListUI.java | 28 +++++++++++++++++++ .../components/ThreeStateCheckBoxPanel.kt | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/platform/platform-api/src/com/intellij/ui/components/WideSelectionListUI.java b/platform/platform-api/src/com/intellij/ui/components/WideSelectionListUI.java index af9085d455a9..1a2aeae8a0ca 100644 --- a/platform/platform-api/src/com/intellij/ui/components/WideSelectionListUI.java +++ b/platform/platform-api/src/com/intellij/ui/components/WideSelectionListUI.java @@ -17,6 +17,8 @@ import javax.swing.*; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicListUI; import java.awt.*; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; import static com.intellij.openapi.util.SystemInfo.isMac; import static com.intellij.ui.paint.RectanglePainter.DRAW; @@ -223,6 +225,32 @@ public final class WideSelectionListUI extends BasicListUI { } } + @Override + protected FocusListener createFocusListener() { + var superFocusListener = super.createFocusListener(); + + // Support selected items background while changing focus + return new FocusListener() { + @Override + public void focusGained(FocusEvent e) { + if (list.getSelectionMode() == ListSelectionModel.SINGLE_SELECTION) { + superFocusListener.focusGained(e); + } else { + list.repaint(); + } + } + + @Override + public void focusLost(FocusEvent e) { + if (list.getSelectionMode() == ListSelectionModel.SINGLE_SELECTION) { + superFocusListener.focusLost(e); + } else { + list.repaint(); + } + } + }; + } + /** @noinspection MethodOverridesStaticMethodOfSuperclass, unused */ public static ComponentUI createUI(JComponent list) { return new WideSelectionListUI(); diff --git a/platform/platform-impl/internal/src/com/intellij/internal/ui/sandbox/components/ThreeStateCheckBoxPanel.kt b/platform/platform-impl/internal/src/com/intellij/internal/ui/sandbox/components/ThreeStateCheckBoxPanel.kt index 59130257b31c..0ecbc45f7227 100644 --- a/platform/platform-impl/internal/src/com/intellij/internal/ui/sandbox/components/ThreeStateCheckBoxPanel.kt +++ b/platform/platform-impl/internal/src/com/intellij/internal/ui/sandbox/components/ThreeStateCheckBoxPanel.kt @@ -10,7 +10,7 @@ import javax.swing.JComponent internal class ThreeStateCheckBoxPanel : UISandboxPanel { - override val title: String = "ThreeStateCheckBoxPanel" + override val title: String = "ThreeStateCheckBox" override fun createContent(disposable: Disposable): JComponent { return panel {