From f81957cd730cb5f5c4af3c4cb095a8bb4cc1f98d Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Fri, 23 Oct 2026 22:34:11 +0100 Subject: [PATCH] feat(app): left/right arrows step through artifacts and changed files --- .../artifacts/ui/artifact_viewer_page.dart | 9 ++++- .../changes/widgets/file_diff_viewer.dart | 18 ++++++--- app/lib/ui/input/arrow_key_pager.dart | 32 +++++++++++++++ app/test/ui/input/arrow_key_pager_test.dart | 40 +++++++++++++++++++ 4 files changed, 92 insertions(+), 7 deletions(-) create mode 100644 app/lib/ui/input/arrow_key_pager.dart create mode 100644 app/test/ui/input/arrow_key_pager_test.dart diff --git a/app/lib/features/artifacts/ui/artifact_viewer_page.dart b/app/lib/features/artifacts/ui/artifact_viewer_page.dart index cbb9a189..5fd4c5f3 100644 --- a/app/lib/features/artifacts/ui/artifact_viewer_page.dart +++ b/app/lib/features/artifacts/ui/artifact_viewer_page.dart @@ -1,3 +1,4 @@ +import '../../../ui/input/arrow_key_pager.dart'; import 'dart:convert'; import 'package:flutter/cupertino.dart'; @@ -219,7 +220,7 @@ class _ArtifactViewerPageState extends State { final title = page == null ? artifactViewerTitle : artifactDisplayName(page.artifact); - final body = page == null || plan == null + Widget body = page == null || plan == null ? const Center(child: Text('No previewable artifacts recorded.')) : ArtifactViewerBody( page: page, @@ -239,6 +240,12 @@ class _ArtifactViewerPageState extends State { onOpen: plan.resolved == null ? () {} : () => _open(plan.resolved!), onCopy: plan.resolved == null ? () {} : () => _copy(plan.resolved!), ); + // Left/right arrows walk the same list as the Previous/Next buttons. + body = ArrowKeyPager( + onPrevious: () => _step(-1), + onNext: () => _step(1), + child: body, + ); if (usesCupertinoHost(context)) { return CupertinoPageScaffold( backgroundColor: CupertinoColors.systemGroupedBackground, diff --git a/app/lib/features/changes/widgets/file_diff_viewer.dart b/app/lib/features/changes/widgets/file_diff_viewer.dart index bfbfdd51..b145c693 100644 --- a/app/lib/features/changes/widgets/file_diff_viewer.dart +++ b/app/lib/features/changes/widgets/file_diff_viewer.dart @@ -1,3 +1,4 @@ +import '../../../ui/input/arrow_key_pager.dart'; import 'dart:async'; import 'package:flutter/cupertino.dart'; @@ -287,12 +288,17 @@ class _FileDiffPageState extends State { onPrevious: _index > 0 ? () => _step(-1) : null, onNext: _index < count - 1 ? () => _step(1) : null, ); - final body = Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - Expanded(child: viewer), - ?pager, - ], + // Left/right arrows step between changed files, like the chevrons. + final body = ArrowKeyPager( + onPrevious: _index > 0 ? () => _step(-1) : null, + onNext: _index < count - 1 ? () => _step(1) : null, + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Expanded(child: viewer), + ?pager, + ], + ), ); if (cupertino) { return CupertinoPageScaffold( diff --git a/app/lib/ui/input/arrow_key_pager.dart b/app/lib/ui/input/arrow_key_pager.dart new file mode 100644 index 00000000..0986c430 --- /dev/null +++ b/app/lib/ui/input/arrow_key_pager.dart @@ -0,0 +1,32 @@ +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +/// Left and right arrow keys step to the previous and next item (an +/// artifact, a changed file) wherever a keyboard is attached. A field that +/// takes the arrows itself (a text box) keeps them while it has focus. +class ArrowKeyPager extends StatelessWidget { + const ArrowKeyPager({ + super.key, + required this.onPrevious, + required this.onNext, + required this.child, + }); + + /// Null at the first item. + final VoidCallback? onPrevious; + + /// Null at the last item. + final VoidCallback? onNext; + final Widget child; + + @override + Widget build(BuildContext context) => CallbackShortcuts( + bindings: { + const SingleActivator(LogicalKeyboardKey.arrowLeft): () => + onPrevious?.call(), + const SingleActivator(LogicalKeyboardKey.arrowRight): () => + onNext?.call(), + }, + child: Focus(autofocus: true, child: child), + ); +} diff --git a/app/test/ui/input/arrow_key_pager_test.dart b/app/test/ui/input/arrow_key_pager_test.dart new file mode 100644 index 00000000..a8bb003e --- /dev/null +++ b/app/test/ui/input/arrow_key_pager_test.dart @@ -0,0 +1,40 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/changes/domain/change_kind.dart'; +import 'package:pipelines_app/features/changes/domain/file_change.dart'; +import 'package:pipelines_app/features/changes/widgets/file_diff_viewer.dart'; + +FileChange _file(String path) => FileChange( + path: path, + kind: ChangeKind.modified, + patch: '--- a/$path\n+++ b/$path\n@@ -1 +1 @@\n-a\n+b\n', +); + +void main() { + testWidgets('left and right arrows step between changed files', ( + tester, + ) async { + await tester.pumpWidget( + MaterialApp( + home: FileDiffPage( + files: [_file('lib/one.dart'), _file('lib/two.dart')], + ), + ), + ); + await tester.pumpAndSettle(); + expect(find.text('one.dart'), findsWidgets); + + await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight); + await tester.pumpAndSettle(); + expect(find.text('two.dart'), findsWidgets); + + // The last file stays put; left goes back. + await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight); + await tester.pumpAndSettle(); + expect(find.text('two.dart'), findsWidgets); + await tester.sendKeyEvent(LogicalKeyboardKey.arrowLeft); + await tester.pumpAndSettle(); + expect(find.text('one.dart'), findsWidgets); + }); +}