8000 fix: always reveal selected node (#203) · sveltejs/svelte-devtools@7603461 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7603461

Browse files
authored
fix: always reveal selected node (#203)
1 parent 266c5e4 commit 7603461

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/routes/+layout.svelte

+13-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import { background } from '$lib/runtime.svelte';
1818
import { app, visibility } from '$lib/state.svelte';
1919
20+
let container = $state<undefined | HTMLElement>();
21+
2022
$effect(() => {
2123
if (app.selected) {
2224
background.send('bridge::ext/select', app.selected.id);
@@ -25,6 +27,16 @@
2527
while ((current = current.parent)) {
2628
current.expanded = true;
2729
}
30+
31+
// scroll selected node into view
32+
if (app.selected.dom && container) {
33+
const { top: start, height } = container.getBoundingClientRect();
34+
const top = app.selected.dom.getBoundingClientRect().top - start< B3F4 /span>;
35+
if (top >= 0 && top + 24 <= height) return; // node is in view
36+
app.selected.dom.scrollIntoView({
37+
block: top < 0 || height / 2 - top >= 0 ? 'start' : 'end',
38+
});
39+
}
2840
} else if (app.root.length) {
2941
app.selected = app.root[0];
3042
}
@@ -115,7 +127,7 @@
115127
</Button>
116128
</Toolbar>
117129

118-
<ul on:mousemove|self={reset} onmouseleave={reset}>
130+
<ul bind:this={container} on:mousemove|self={reset} onmouseleave={reset}>
119131
{#each app.root as node (node.id)}
120132
<Node {node} />
121133
{/each}

0 commit comments

Comments
 (0)
0