Skip to content

Commit

Permalink
Support expand/collapsing hideable implementation detail groups with …
Browse files Browse the repository at this point in the history
…left and right arrow keys (#8275)
  • Loading branch information
elliette authored Sep 23, 2024
1 parent 34bf480 commit cbf2d55
Showing 1 changed file with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@ class InspectorTreeController extends DisposableController

void navigateLeft() {
final selectionLocal = selection;
final diagnostic = selectionLocal?.diagnostic;

final toggledHideableGroup =
_maybeToggleHideableGroup(diagnostic, showGroup: false);
if (toggledHideableGroup) return;

// This logic is consistent with how IntelliJ handles tree navigation on
// on left arrow key press.
Expand All @@ -342,11 +347,16 @@ class InspectorTreeController extends DisposableController
}

void navigateRight() {
final selectionLocal = selection;
final diagnostic = selectionLocal?.diagnostic;

final toggledHideableGroup =
_maybeToggleHideableGroup(diagnostic, showGroup: true);
if (toggledHideableGroup) return;

// This logic is consistent with how IntelliJ handles tree navigation on
// on right arrow key press.

final selectionLocal = selection;

if (selectionLocal == null || selectionLocal.isExpanded) {
_navigateHelper(1);
return;
Expand All @@ -373,6 +383,31 @@ class InspectorTreeController extends DisposableController
);
}

/// Given [shouldShow], toggles the visibility of a hideable group.
///
/// Returns a [bool] representing whether or not the group was toggled.
bool _maybeToggleHideableGroup(
RemoteDiagnosticsNode? diagnostic, {
required bool showGroup,
}) {
final isHideableGroupLeader =
diagnostic != null && diagnostic.isHideableGroupLeader;
final shouldToggle = isHideableGroupLeader &&
(showGroup ? diagnostic.groupIsHidden : !diagnostic.groupIsHidden);

if (shouldToggle) {
refreshTree(
updateTreeAction: () {
diagnostic.toggleHiddenGroup();
return true;
},
);
return true;
}

return false;
}

double get horizontalPadding => 10.0;

/// Returns the indentation of a row at the given [depth] in the inspector.
Expand Down

0 comments on commit cbf2d55

Please sign in to comment.