expand_to_tags

Contents

expand_to_tags#

penzai.treescope.foldable_representation.layout_algorithms.expand_to_tags(tree: RenderableTreePart, tags: Collection[Any], collapse_weak_others: bool) None[source]#

Expands a tree so that any part with a tag in the given set is fisible.

This function ignores the existing expand state, and instead just ensures that every foldable node that contains a tag in tags is expanded. Optionally it will also ensure that all sibling foldable nodes are collapsed.

Expand states for those nodes are set to EXPANDED or COLLAPSED, and expand states for other nodes are not modified. This means you can call expand_for_balanced_layout after this function to reformat the subtrees of tree that haven’t yet been assigned strong expand/collapse states. This is useful for producing balanced layouts once the user expands a collapsed node.

Parameters:
  • tree – The tree to update.

  • tags – The tags that should be made visible.

  • collapse_weak_others – Whether to collapse foldables that do NOT have the given tags and have a weak expansion state.