Skip to content

Commit 513c68b

Browse files
committed
Skip text and anchor nodes
1 parent 72ca77e commit 513c68b

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/store.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ export const searchValue = writable('')
1616
export const profilerEnabled = writable(false)
1717
export const profileFrame = writable({})
1818

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+
1926
window.addEventListener('keydown', e => {
2027
if (e.target !== document.body) return
2128

2229
selectedNode.update(node => {
23-
console.log(e, node)
2430
if (node.invalidate === undefined) return node
2531
switch (e.key) {
2632
case 'Enter':
@@ -34,17 +40,17 @@ window.addEventListener('keydown', e => {
3440
return node
3541

3642
case 'ArrowDown': {
37-
const _visibility = get(visibility)
38-
const children = node.children.filter(o => _visibility[o.type])
43+
const children = interactableNodes(node.children)
3944

4045
if (node.collapsed || children.length === 0) {
4146
var next = node
4247
var current = node
4348
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+
)
4854
const index = siblings.findIndex(o => o.id === current.id)
4955
next = siblings[index + 1]
5056

@@ -63,11 +69,9 @@ window.addEventListener('keydown', e => {
6369
return node
6470

6571
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+
)
7175
const index = siblings.findIndex(o => o.id === node.id)
7276
return index > 0 ? siblings[index - 1] : node.parent ?? node
7377
}

0 commit comments

Comments
 (0)