Keep Files breadcrumbs aligned to the current folder
Pin the horizontally scrolling breadcrumb to its trailing edge so deep paths keep the current folder visible. Preserve tappable navigation, middle-ellipsize long labels, and cover the behavior with focused widget tests and the rendered fixture.
This commit is contained in:
@@ -97,19 +97,11 @@ class FilesHeader extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
if (listing != null)
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
for (final crumb in folderCrumbs(listing.home, listing.path))
|
||||
TextButton(
|
||||
onPressed: controller.loading
|
||||
? null
|
||||
: () => controller.open(crumb.path),
|
||||
child: Text(crumb.label),
|
||||
),
|
||||
],
|
||||
),
|
||||
_FilesBreadcrumbs(
|
||||
home: listing.home,
|
||||
path: listing.path,
|
||||
loading: controller.loading,
|
||||
onOpen: controller.open,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
@@ -142,3 +134,114 @@ class FilesHeader extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _FilesBreadcrumbs extends StatefulWidget {
|
||||
const _FilesBreadcrumbs({
|
||||
required this.home,
|
||||
required this.path,
|
||||
required this.loading,
|
||||
required this.onOpen,
|
||||
});
|
||||
|
||||
final String home;
|
||||
final String path;
|
||||
final bool loading;
|
||||
final ValueChanged<String> onOpen;
|
||||
|
||||
@override
|
||||
State<_FilesBreadcrumbs> createState() => _FilesBreadcrumbsState();
|
||||
}
|
||||
|
||||
class _FilesBreadcrumbsState extends State<_FilesBreadcrumbs> {
|
||||
final ScrollController _scroll = ScrollController();
|
||||
double? _lastWidth;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_pinToEnd();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant _FilesBreadcrumbs oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.path != widget.path) _pinToEnd();
|
||||
}
|
||||
|
||||
void _pinToEnd() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted && _scroll.hasClients) {
|
||||
_scroll.jumpTo(_scroll.position.maxScrollExtent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_scroll.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final crumbs = folderCrumbs(widget.home, widget.path);
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final surface = Theme.of(context).colorScheme.surface;
|
||||
if (_lastWidth != constraints.maxWidth) {
|
||||
_lastWidth = constraints.maxWidth;
|
||||
_pinToEnd();
|
||||
}
|
||||
return SizedBox(
|
||||
width: constraints.maxWidth,
|
||||
height: kMinInteractiveDimension,
|
||||
child: Stack(
|
||||
children: [
|
||||
SingleChildScrollView(
|
||||
key: const Key('files-breadcrumb-scroll'),
|
||||
controller: _scroll,
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
for (var index = 0; index < crumbs.length; index++)
|
||||
TextButton(
|
||||
onPressed: widget.loading
|
||||
? null
|
||||
: () => widget.onOpen(crumbs[index].path),
|
||||
child: Text(
|
||||
_middleEllipsis(crumbs[index].label),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
IgnorePointer(
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Container(
|
||||
width: 20,
|
||||
height: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [surface, surface.withValues(alpha: 0)],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _middleEllipsis(String label, {int maxCharacters = 36}) {
|
||||
if (label.length <= maxCharacters) return label;
|
||||
final visible = maxCharacters - 1;
|
||||
final leading = (visible + 1) ~/ 2;
|
||||
final trailing = visible - leading;
|
||||
return '${label.substring(0, leading)}…${label.substring(label.length - trailing)}';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# Files path breadcrumb
|
||||
|
||||
Implemented an end-aligned, horizontally scrollable breadcrumb for the chat
|
||||
Files panel. It pins to the newest folder after navigation and layout changes,
|
||||
keeps every segment tappable, allows manual scrolling to earlier segments, fades
|
||||
the leading edge, and middle-ellipsizes long segment labels.
|
||||
|
||||
Affected states: deep paths, navigation to a new folder, tapping an earlier
|
||||
segment, and resized/bounded panel layouts. The implementation is shared by
|
||||
phone and desktop Material layouts and does not depend on theme brightness.
|
||||
|
||||
Focused regression: `files_panel_test.dart` verifies the deep leaf remains
|
||||
fully visible at the trailing edge, deeper navigation pins the new leaf,
|
||||
middle-ellipsizes long labels, and tapping an earlier segment requests that
|
||||
folder. `tool/memwatch/full.sh 'test/features/chat/files/files_panel_test.dart'`
|
||||
passes (17 tests); `tool/analyze.sh` is clean. The capture fixture now starts at
|
||||
a deep path and includes a long folder entry for rendered review.
|
||||
@@ -21,14 +21,20 @@ class Gateway extends PipelinesClient {
|
||||
@override
|
||||
Uri get endpoint => Uri.parse('ws://example.test/connect');
|
||||
bool fail = false;
|
||||
final requestedPaths = <String>[];
|
||||
@override
|
||||
Stream<JsonMap> get frames => const Stream.empty();
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
||||
if (fail) throw StateError('internal transport secret');
|
||||
final request = fields['list_directory'];
|
||||
final path = request is Map && request['path'] is String
|
||||
? request['path'] as String
|
||||
: '/home/demo';
|
||||
requestedPaths.add(path);
|
||||
return {
|
||||
'directory_listing': {
|
||||
'path': '/home/demo',
|
||||
'path': path,
|
||||
'home': '/home',
|
||||
'entries': [
|
||||
for (final name in [
|
||||
@@ -55,10 +61,11 @@ void main() {
|
||||
WidgetTester tester, {
|
||||
Gateway? gateway,
|
||||
FilesViewer? viewer,
|
||||
String initialPath = '/home/demo',
|
||||
}) async {
|
||||
final controller = FilesController(
|
||||
gateway: gateway ?? Gateway(),
|
||||
initialPath: '/home/demo',
|
||||
initialPath: initialPath,
|
||||
);
|
||||
addTearDown(controller.dispose);
|
||||
await tester.pumpWidget(
|
||||
@@ -93,6 +100,79 @@ void main() {
|
||||
expect(find.widgetWithText(TextButton, 'demo'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'deep breadcrumbs keep the leaf fully visible at the trailing edge',
|
||||
(tester) async {
|
||||
final gateway = Gateway();
|
||||
await pump(
|
||||
tester,
|
||||
gateway: gateway,
|
||||
initialPath:
|
||||
'/home/alpha/beta/gamma/delta/epsilon/zeta/eta/theta/iota/omega',
|
||||
);
|
||||
|
||||
final scroll = tester.widget<SingleChildScrollView>(
|
||||
find.byKey(const Key('files-breadcrumb-scroll')),
|
||||
);
|
||||
expect(find.text('omega'), findsOneWidget);
|
||||
expect(
|
||||
scroll.controller!.position.pixels,
|
||||
scroll.controller!.position.maxScrollExtent,
|
||||
);
|
||||
final viewport = tester.getRect(
|
||||
find.byKey(const Key('files-breadcrumb-scroll')),
|
||||
);
|
||||
final leaf = tester.getRect(find.text('omega'));
|
||||
final leafButton = tester.getRect(
|
||||
find.widgetWithText(TextButton, 'omega'),
|
||||
);
|
||||
expect(leaf.right, lessThanOrEqualTo(viewport.right));
|
||||
expect(leafButton.right, closeTo(viewport.right, 1));
|
||||
|
||||
scroll.controller!.jumpTo(0);
|
||||
await tester.pump();
|
||||
await tester.tap(find.widgetWithText(TextButton, 'alpha'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.requestedPaths.last, '/home/alpha');
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('navigating deeper pins the new breadcrumb leaf', (tester) async {
|
||||
final gateway = Gateway();
|
||||
final controller = await pump(
|
||||
tester,
|
||||
gateway: gateway,
|
||||
initialPath: '/home/alpha/beta',
|
||||
);
|
||||
|
||||
await controller.open('/home/alpha/beta/gamma/delta/leaf');
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final scroll = tester.widget<SingleChildScrollView>(
|
||||
find.byKey(const Key('files-breadcrumb-scroll')),
|
||||
);
|
||||
expect(find.text('leaf'), findsOneWidget);
|
||||
expect(
|
||||
scroll.controller!.position.pixels,
|
||||
scroll.controller!.position.maxScrollExtent,
|
||||
);
|
||||
expect(gateway.requestedPaths.last, '/home/alpha/beta/gamma/delta/leaf');
|
||||
});
|
||||
|
||||
testWidgets('long breadcrumb labels use middle ellipsis', (tester) async {
|
||||
await pump(
|
||||
tester,
|
||||
initialPath:
|
||||
'/home/a-folder-name-that-is-long-enough-to-ellipsize-in-the-middle',
|
||||
);
|
||||
|
||||
expect(find.text('a-folder-name-that…ize-in-the-middle'), findsOneWidget);
|
||||
expect(
|
||||
find.text('a-folder-name-that-is-long-enough-to-ellipsize-in-the-middle'),
|
||||
findsNothing,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('file sorting uses a sort icon and preserves direction', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/files/files_urls.dart';
|
||||
|
||||
/// A static, two-level explorer fixture. Its files live in capture/fixtures/files.
|
||||
/// A static explorer fixture with a deep starting path and a long folder name.
|
||||
/// Its files live in capture/fixtures/files.
|
||||
JsonMap probeFilesReply(JsonMap request) {
|
||||
final fields = request['list_directory'] as Map?;
|
||||
final path = '${fields?['path'] ?? '/srv/probe/release'}';
|
||||
final requestedPath = '${fields?['path'] ?? '/srv/probe/release'}';
|
||||
final path = requestedPath == '/srv/probe/release'
|
||||
? '/srv/probe/release/operations/2026/quarterly/release-candidate'
|
||||
: requestedPath;
|
||||
final nested = path.endsWith('/assets');
|
||||
final entries = nested
|
||||
? <(String, int)>[('design.png', 18432), ('icon.jpg', 23000)]
|
||||
@@ -31,6 +35,12 @@ JsonMap probeFilesReply(JsonMap request) {
|
||||
'entries': [
|
||||
if (!nested) ...[
|
||||
{'name': 'assets', 'path': '$path/assets', 'is_dir': true},
|
||||
{
|
||||
'name': 'a-folder-name-that-is-long-enough-to-ellipsize-in-the-middle',
|
||||
'path':
|
||||
'$path/a-folder-name-that-is-long-enough-to-ellipsize-in-the-middle',
|
||||
'is_dir': true,
|
||||
},
|
||||
{
|
||||
'name': '.config',
|
||||
'path': '$path/.config',
|
||||
|
||||
Reference in New Issue
Block a user