Merge pull request #201 from gaearon/scroll-fix

Fix scrolling to selected row in collapsed mode
This commit is contained in:
Brian Vaughn
2019-04-22 09:37:15 -07:00
committed by GitHub
2 changed files with 29 additions and 0 deletions
+15
View File
@@ -429,6 +429,21 @@ export default class Store extends EventEmitter {
return null;
}
isInsideCollapsedSubTree(id: number): boolean {
let current = this._idToElement.get(id);
while (current != null) {
if (current.parentID === 0) {
return false;
} else {
current = this._idToElement.get(current.parentID);
if (current != null && current.isCollapsed) {
return true;
}
}
}
return false;
}
startProfiling(): void {
this._bridge.send('startProfiling');
@@ -596,6 +596,20 @@ function TreeContextController({ children, viewElementSource }: Props) {
state = reduceTreeState(store, state, action);
state = reduceSearchState(store, state, action);
state = reduceOwnersState(store, state, action);
// If the selected ID is in a collapsed subtree, reset the selected index to null.
// We'll know the correct index after the layout effect will toggle the tree,
// and the store tree is mutated to account for that.
if (
state.selectedElementID !== null &&
store.isInsideCollapsedSubTree(state.selectedElementID)
) {
return {
...state,
selectedElementIndex: null,
};
}
return state;
default:
throw new Error(`Unrecognized action "${type}"`);