@@ -16,11 +16,17 @@ export const searchValue = writable('')
16
16
export const profilerEnabled = writable ( false )
17
17
export const profileFrame = writable ( { } )
18
18
19
+ function interactableNodes ( list ) {
20
+ const _visibility = get ( visibility )
21
+ return list . filter (
22
+ o => _visibility [ o . type ] && o . type !== 'text' && o . type !== 'anchor'
23
+ )
24
+ }
25
+
19
26
window . addEventListener ( 'keydown' , e => {
20
27
if ( e . target !== document . body ) return
21
28
22
29
selectedNode . update ( node => {
23
- console . log ( e , node )
24
30
if ( node . invalidate === undefined ) return node
25
31
switch ( e . key ) {
26
32
case 'Enter' :
@@ -34,17 +40,17 @@ window.addEventListener('keydown', e => {
34
40
return node
35
41
36
42
case 'ArrowDown' : {
37
- const _visibility = get ( visibility )
38
- const children = node . children . filter ( o => _visibility [ o . type ] )
43
+ const children = interactableNodes ( node . children )
39
44
40
45
if ( node . collapsed || children . length === 0 ) {
41
46
var next = node
42
47
var current = node
43
48
do {
44
- const siblings = ( current . parent === undefined
45
- ? get ( rootNodes )
46
- : current . parent . children
47
- ) . filter ( o => _visibility [ o . type ] )
49
+ const siblings = interactableNodes (
50
+ current . parent === undefined
51
+ ? get ( rootNodes )
52
+ : current . parent . children
53
+ )
48
54
const index = siblings . findIndex ( o => o . id === current . id )
49
55
next = siblings [ index + 1 ]
50
56
@@ -63,11 +69,9 @@ window.addEventListener('keydown', e => {
63
69
return node
64
70
65
71
case 'ArrowUp' : {
66
- const _visibility = get ( visibility )
67
- const siblings = ( node . parent === undefined
68
- ? get ( rootNodes )
69
- : node . parent . children
70
- ) . filter ( o => _visibility [ o . type ] )
72
+ const siblings = interactableNodes (
73
+ node . parent === undefined ? get ( rootNodes ) : node . parent . children
74
+ )
71
75
const index = siblings . findIndex ( o => o . id === node . id )
72
76
return index > 0 ? siblings [ index - 1 ] : node . parent ?? node
73
77
}
0 commit comments