| 176 | } |
| 177 | |
| 178 | getLastKey() { |
| 179 | // Find the deepest expanded child. We don't use collection.getLastKey() here |
| 180 | // because that will return the deepest child regardless of expandedKeys. |
| 181 | // Instead, start from the last top-level key and walk down. |
| 182 | let key = this.lastKey; |
| 183 | if (key == null) { |
| 184 | return null; |
| 185 | } |
| 186 | |
| 187 | let node = this.getItem(key) as CollectionNode<T>; |
| 188 | |
| 189 | while ( |
| 190 | node?.lastChildKey != null && |
| 191 | (node.type !== 'item' || this.expandedKeys.has(node.key)) |
| 192 | ) { |
| 193 | node = this.getItem(node.lastChildKey) as CollectionNode<T>; |
| 194 | } |
| 195 | |
| 196 | return node?.key; |
| 197 | } |
| 198 | |
| 199 | getKeyAfter(key: Key) { |
| 200 | let node = this.getItem(key) as CollectionNode<T>; |