Skip to content

Commit 64ada61

Browse files
authored
fix: recursively checks for invisible nodes (#165)
1 parent a5c245d commit 64ada61

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/lib/nodes/Element.svelte

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import type { ComponentProps } from 'svelte';
77
88
export let tagName: string;
9-
export let hasChildren: boolean;
9+
export let empty: boolean;
1010
export let expanded: boolean;
1111
1212
export let attributes: ComponentProps<ElementAttributes>['attributes'];
@@ -48,7 +48,16 @@
4848
});
4949
</script>
5050

51-
{#if hasChildren}
51+
{#if empty}
52+
<div>
53+
<span>&lt;</span>
54+
<span class="tag-name">
55+
<Indexer text={tagName} />
56+
</span>
57+
<ElementAttributes attributes={cached} {listeners} />
58+
<span>&nbsp;/&gt;</span>
59+
</div>
60+
{:else}
5261
<div role="group" class:expanded class="expandable" on:dblclick={() => (expanded = !expanded)}>
5362
<span>&lt;</span>
5463
<span class="tag-name">
@@ -76,15 +85,6 @@
7685
<span>&gt;</span>
7786
</div>
7887
{/if}
79-
{:else}
80-
<div>
81-
<span>&lt;</span>
82-
<span class="tag-name">
83-
<Indexer text={tagName} />
84-
</span>
85-
<ElementAttributes attributes={cached} {listeners} />
86-
<span>&nbsp;/&gt;</span>
87-
</div>
8888
{/if}
8989

9090
<style>

src/lib/nodes/Node.svelte

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55
import Slot from './Slot.svelte';
66
77
import { background } from '$lib/runtime';
8-
import { visibility, hovered, selected } from '$lib/store';
8+
import { hovered, selected, visibility } from '$lib/store';
99
1010
export let node: NonNullable<typeof $selected>;
1111
export let depth = 1;
1212
1313
node.invalidate = () => (node = node);
1414
15+
function invisible(n: typeof node): boolean {
16+
return !$visibility[n.type] && n.children.every(invisible);
17+
}
18+
1519
let lastLength = node.children.length;
1620
let flash = false;
1721
$: {
@@ -42,7 +46,7 @@
4246
tagName={node.tagName}
4347
attributes={node.detail?.attributes || []}
4448
listeners={node.detail?.listeners || []}
45-
hasChildren={!!node.children.length}
49+
empty={!node.children.length || node.children.every(invisible)}
4650
bind:expanded={node.expanded}
4751
>
4852
<ul>

0 commit comments

Comments
 (0)