fix(jetbrains): hide expanded diff folder badges

Expanded folders already reveal child file badges, so showing the rolled-up folder total duplicates the visible counts. Keep aggregate badges only on collapsed folders while preserving file badges.
This commit is contained in:
kirillk
2026-07-31 16:33:30 -04:00
parent 632e4ca8c0
commit e0fa585e33
2 changed files with 41 additions and 6 deletions
@@ -623,9 +623,12 @@ private class Renderer : JPanel(BorderLayout()), TreeCellRenderer {
val name = item?.name?.ifBlank { item.path }.orEmpty()
val color = item?.file?.let(::fileStatus)?.color
if (color == null) text.append(name) else text.append(name, SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, color))
val changed = item != null && (item.additions != 0 || item.deletions != 0)
badge.isVisible = changed
if (changed) badge.update(item.additions, item.deletions)
// A folder's badge rolls up its descendants' stats, which is only meaningful while the
// folder is collapsed. Once expanded the child rows carry their own badges, so hide the
// folder aggregate to avoid duplicating the numbers. Leaf files always show their badge.
val show = item != null && (item.additions != 0 || item.deletions != 0) && !(item.dir && expanded)
badge.isVisible = show
if (show) badge.update(item.additions, item.deletions)
return this
}
}
@@ -127,6 +127,36 @@ class KiloDiffEditorContentTest : BasePlatformTestCase() {
}
}
fun `test folder badge shows only while collapsed`() {
val parent = Disposer.newDisposable()
try {
val view = view(files(), parent)
val tree = components(view).filterIsInstance<Tree>().single()
val folder = folder(tree)
tree.expandPath(TreePath(folder.path))
assertFalse("expanded folder hides its rolled-up badge", rowBadge(renderer(tree, folder)).isVisible)
tree.collapsePath(TreePath(folder.path))
assertTrue("collapsed folder shows its rolled-up badge", rowBadge(renderer(tree, folder)).isVisible)
} finally {
Disposer.dispose(parent)
}
}
fun `test leaf badge stays visible while its folder is expanded`() {
val parent = Disposer.newDisposable()
try {
val view = view(files(), parent)
val tree = components(view).filterIsInstance<Tree>().single()
tree.expandPath(TreePath(folder(tree).path))
assertTrue(rowBadge(renderer(tree, leaf(tree))).isVisible)
} finally {
Disposer.dispose(parent)
}
}
fun `test row badge hidden when node has no changes`() {
val parent = Disposer.newDisposable()
try {
@@ -442,12 +472,14 @@ class KiloDiffEditorContentTest : BasePlatformTestCase() {
false,
)
private fun leaf(tree: Tree): DefaultMutableTreeNode {
private fun folder(tree: Tree): DefaultMutableTreeNode {
val root = tree.model.root as DefaultMutableTreeNode
val src = root.getChildAt(0) as DefaultMutableTreeNode
return src.getChildAt(0) as DefaultMutableTreeNode
return root.getChildAt(0) as DefaultMutableTreeNode
}
private fun leaf(tree: Tree): DefaultMutableTreeNode =
folder(tree).getChildAt(0) as DefaultMutableTreeNode
private fun rowBadge(row: Component): DiffStatBadge = components(row).filterIsInstance<DiffStatBadge>().single()
private fun banner(editor: DiffEditorView): EditorNotificationPanel = components(editor.component)