(rememberedSelection: SelectionStorage)
| 366 | } |
| 367 | |
| 368 | public adaptSelection(rememberedSelection: SelectionStorage): SelectionStorage { |
| 369 | if (!this.graph.nodeMap || !(rememberedSelection instanceof SelectionStorage)) { |
| 370 | return new SelectionStorage(); |
| 371 | } |
| 372 | |
| 373 | for (const node of rememberedSelection.adaptedNodes) { |
| 374 | this.graph.makeNodeVisible(node); |
| 375 | } |
| 376 | |
| 377 | for (const [key, node] of rememberedSelection.nodes.entries()) { |
| 378 | // Adding survived nodes (with the same id) |
| 379 | const survivedNode = this.graph.nodeMap[key]; |
| 380 | if (survivedNode) { |
| 381 | const key = this.state.selection.stringKey(survivedNode); |
| 382 | rememberedSelection.adaptNode(key); |
| 383 | this.graph.makeNodeVisible(key); |
| 384 | } |
| 385 | // Adding children of nodes |
| 386 | const childNodes = this.graph.originNodesMap.get(key); |
| 387 | if (childNodes?.length > 0) { |
| 388 | for (const childNode of childNodes) { |
| 389 | const key = this.state.selection.stringKey(childNode); |
| 390 | rememberedSelection.adaptNode(key); |
| 391 | this.graph.makeNodeVisible(key); |
| 392 | } |
| 393 | } |
| 394 | // Adding ancestors of nodes |
| 395 | const originStringKey = this.state.selection.originStringKey(node); |
| 396 | if (originStringKey) { |
| 397 | rememberedSelection.adaptNode(originStringKey); |
| 398 | this.graph.makeNodeVisible(originStringKey); |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | return rememberedSelection; |
| 403 | } |
| 404 | |
| 405 | private initializeNodeSelectionHandler(): NodeSelectionHandler & ClearableHandler { |
| 406 | const view = this; |
no test coverage detected