IJPL-160982 Skip !isIncludedInExpandAll descendants in Expand Selected

Just like in Expand All, if a descendant node doesn't want to be expanded,
we need to skip those here too. An example: those huge Libraries nodes
in the Packages View pane. Nobody ever wants to expand everything
that's in them.

A small difference from the Expand All action: if such a node is actually
selected, and the user presses Expand Selected, we still expand it.
It would make little sense if the action just did nothing in such a case.

GitOrigin-RevId: b02b70b14a81d80d0f24272cb546ed4cfdcc0055
This commit is contained in:
Sergei Tachenov
2024-08-27 10:14:38 +03:00
committed by intellij-monorepo-bot
parent 93df1a26bc
commit 3857272e7d

View File

@@ -34,8 +34,10 @@ class ExpandRecursivelyAction : DumbAwareAction(), CustomComponentAction, Action
selection.any { selectedPath ->
// N.B.: isDescendant is very poorly named: a.isDescendant(b) means "b is a descendant of a".
when {
// Descendants of the selected paths are expanded.
selectedPath.isDescendant(path) -> true
// Selected paths are expanded unconditionally.
path == selectedPath -> true
// Descendants of the selected paths are expanded unless they explicitly don't want that.
selectedPath.isDescendant(path) -> path.isIncludedInExpandAll
// This unusual isDescendant condition is needed because TreeUtil won't even visit
// children if the parent doesn't match, so it'll just stop at the root node.
// So even though the parents of the selected paths are obviously already expanded,
@@ -72,3 +74,10 @@ class ExpandRecursivelyAction : DumbAwareAction(), CustomComponentAction, Action
}
}
}
private val TreePath.isIncludedInExpandAll: Boolean
get() {
// Include by default, unless the node can and does tell us otherwise.
val node = TreeUtil.getLastUserObject(this) as? AbstractTreeNode<*> ?: return true
return node.isIncludedInExpandAll
}