| 578 | } |
| 579 | |
| 580 | function getHighlightedSibling( |
| 581 | state: ColumnViewState, |
| 582 | nodeTable: NodeTable, |
| 583 | direction: -1 | 1 |
| 584 | ): string | undefined { |
| 585 | const { highlightedNodeId } = state; |
| 586 | |
| 587 | if (!highlightedNodeId) { |
| 588 | return; |
| 589 | } |
| 590 | |
| 591 | const highlightedNode = nodeTable[highlightedNodeId]; |
| 592 | |
| 593 | if (!highlightedNode || !highlightedNode.parentId) { |
| 594 | return; |
| 595 | } |
| 596 | |
| 597 | const parentNode = nodeTable[highlightedNode.parentId]; |
| 598 | |
| 599 | if (!parentNode) { |
| 600 | return; |
| 601 | } |
| 602 | |
| 603 | const highlightedIndex = parentNode.children.indexOf(highlightedNodeId); |
| 604 | const nextIndex = highlightedIndex + direction; |
| 605 | |
| 606 | if (parentNode.children.length <= nextIndex || nextIndex < 0) { |
| 607 | return; |
| 608 | } |
| 609 | |
| 610 | const nextNodeId = parentNode.children[nextIndex]; |
| 611 | |
| 612 | return nextNodeId; |
| 613 | } |