File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change 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 );
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 ;
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 }
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 }
You can’t perform that action at this time.
0 commit comments