Skip to content

Commit

Permalink
Scroll to selected node after switching inspectors (#8379)
Browse files Browse the repository at this point in the history
  • Loading branch information
elliette authored Oct 1, 2024
1 parent 1190641 commit acb2889
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ class InspectorTreeController extends DisposableController

void scrollToRect(Rect targetRect) {
for (final client in _clients) {
client.scrollToRect(targetRect);
client.waitForClientsThenScrollToRect(targetRect);
}
}

Expand Down Expand Up @@ -853,6 +853,8 @@ extension RemoteDiagnosticsNodeExtension on RemoteDiagnosticsNode {
abstract class InspectorControllerClient {
void scrollToRect(Rect rect);

void waitForClientsThenScrollToRect(Rect rect, {int retries});

void requestFocus();
}

Expand Down Expand Up @@ -916,6 +918,10 @@ class _InspectorTreeState extends State<InspectorTree>
readyWhen: (triggerValue) => !triggerValue,
);
}

WidgetsBinding.instance.addPostFrameCallback((_) {
controller.animateTo(controller.selectedNode.value);
});
}

@override
Expand Down Expand Up @@ -964,6 +970,19 @@ class _InspectorTreeState extends State<InspectorTree>
// );
// }

@override
Future<void> waitForClientsThenScrollToRect(
Rect rect, {
int retries = 5,
}) async {
if (_scrollControllerY.hasClients || _scrollControllerX.hasClients) {
return scrollToRect(rect);
}
if (retries == 0) return;
await Future.delayed(const Duration(milliseconds: 20));
return waitForClientsThenScrollToRect(rect, retries: retries - 1);
}

@override
Future<void> scrollToRect(Rect rect) async {
if (rect == _currentAnimateTarget) {
Expand Down

0 comments on commit acb2889

Please sign in to comment.