feat(app): left/right arrows step through artifacts and changed files
This commit is contained in:
@@ -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<ArtifactViewerPage> {
|
||||
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<ArtifactViewerPage> {
|
||||
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,
|
||||
|
||||
@@ -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<FileDiffPage> {
|
||||
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(
|
||||
|
||||
@@ -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),
|
||||
);
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user