Skip to content

feat: shift + click to expand all child components #1752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Sep 24, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ export default defineComponent({
}
}

function switchToggle (event) {
if (event.altKey) {
toggle(true, !expanded.value)
} else {
toggle()
}
}

return {
toggleEl,
sortedChildren,
Expand All @@ -148,7 +156,7 @@ export default defineComponent({
selected,
select,
expanded,
toggle,
switchToggle,
highlight,
unhighlight,
selectNextSibling,
Expand Down Expand Up @@ -180,7 +188,7 @@ export default defineComponent({
:class="{
'invisible': !instance.hasChildren
}"
@click.stop="toggle()"
@click.stop="switchToggle"
>
<span
:class="{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,18 @@ export function useComponent (instance: Ref<ComponentTreeNode>) {
const isExpanded = computed(() => isComponentOpen(instance.value.id))
const isExpandedUndefined = computed(() => expandedMap.value[instance.value.id] == null)

function toggleExpand () {
if (!instance.value.hasChildren) return
setComponentOpen(instance.value.id, !isExpanded.value)
if (isComponentOpen(instance.value.id)) {
requestComponentTree(instance.value.id)
function toggleExpand (recursively = false, value?, child?) {
const treeNode = child || instance.value
if (!treeNode.hasChildren) return
const isOpen = value === undefined ? !isExpanded.value : value
setComponentOpen(treeNode.id, isOpen)
if (isComponentOpen(treeNode.id)) {
requestComponentTree(treeNode.id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would also need to expand the nodes that are loaded after that (recursively).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added property autoOpen to TreeNode to resolve it.

}
if (recursively) {
treeNode.children.forEach(child => {
toggleExpand(recursively, value, child)
})
}
}

Expand Down