(scopeRef: ScopeRef)
| 1041 | } |
| 1042 | |
| 1043 | removeTreeNode(scopeRef: ScopeRef): void { |
| 1044 | // never remove the root |
| 1045 | if (scopeRef === null) { |
| 1046 | return; |
| 1047 | } |
| 1048 | let node = this.fastMap.get(scopeRef); |
| 1049 | if (!node) { |
| 1050 | return; |
| 1051 | } |
| 1052 | let parentNode = node.parent; |
| 1053 | // when we remove a scope, check if any sibling scopes are trying to restore focus to something inside the scope we're removing |
| 1054 | // if we are, then replace the siblings restore with the restore from the scope we're removing |
| 1055 | for (let current of this.traverse()) { |
| 1056 | if ( |
| 1057 | current !== node && |
| 1058 | node.nodeToRestore && |
| 1059 | current.nodeToRestore && |
| 1060 | node.scopeRef && |
| 1061 | node.scopeRef.current && |
| 1062 | isElementInScope(current.nodeToRestore, node.scopeRef.current) |
| 1063 | ) { |
| 1064 | current.nodeToRestore = node.nodeToRestore; |
| 1065 | } |
| 1066 | } |
| 1067 | let children = node.children; |
| 1068 | if (parentNode) { |
| 1069 | parentNode.removeChild(node); |
| 1070 | if (children.size > 0) { |
| 1071 | children.forEach(child => parentNode && parentNode.addChild(child)); |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | this.fastMap.delete(node.scopeRef); |
| 1076 | } |
| 1077 | |
| 1078 | // Pre Order Depth First |
| 1079 | *traverse(node: TreeNode = this.root): Generator<TreeNode> { |
no test coverage detected