From 56f18acf78604490f446855171f6b3cb7e7d4dd6 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Mon, 26 Oct 2026 18:41:44 +0000 Subject: [PATCH] fix(app): close the artifact viewer with Escape --- .../artifacts/ui/artifact_viewer_page.dart | 2 ++ app/lib/ui/input/arrow_key_pager.dart | 8 +++++ .../ui/artifact_viewer_page_test.dart | 34 +++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/app/lib/features/artifacts/ui/artifact_viewer_page.dart b/app/lib/features/artifacts/ui/artifact_viewer_page.dart index 526e5800..92113adc 100644 --- a/app/lib/features/artifacts/ui/artifact_viewer_page.dart +++ b/app/lib/features/artifacts/ui/artifact_viewer_page.dart @@ -245,6 +245,8 @@ class _ArtifactViewerPageState extends State { body = ArrowKeyPager( onPrevious: () => _step(-1), onNext: () => _step(1), + // Escape closes the viewer, like the web's overlay. + onEscape: () => Navigator.of(context).maybePop(), child: body, ); if (usesCupertinoHost(context)) { diff --git a/app/lib/ui/input/arrow_key_pager.dart b/app/lib/ui/input/arrow_key_pager.dart index 0986c430..47b289f7 100644 --- a/app/lib/ui/input/arrow_key_pager.dart +++ b/app/lib/ui/input/arrow_key_pager.dart @@ -9,6 +9,7 @@ class ArrowKeyPager extends StatelessWidget { super.key, required this.onPrevious, required this.onNext, + this.onEscape, required this.child, }); @@ -17,6 +18,10 @@ class ArrowKeyPager extends StatelessWidget { /// Null at the last item. final VoidCallback? onNext; + + /// Escape, when the surface can be dismissed (a viewer page). Absent means + /// Escape keeps whatever meaning the surrounding page gives it. + final VoidCallback? onEscape; final Widget child; @override @@ -26,6 +31,9 @@ class ArrowKeyPager extends StatelessWidget { onPrevious?.call(), const SingleActivator(LogicalKeyboardKey.arrowRight): () => onNext?.call(), + if (onEscape != null) + const SingleActivator(LogicalKeyboardKey.escape): () => + onEscape!.call(), }, child: Focus(autofocus: true, child: child), ); diff --git a/app/test/features/artifacts/ui/artifact_viewer_page_test.dart b/app/test/features/artifacts/ui/artifact_viewer_page_test.dart index 9d1acd0d..0b45f9bc 100644 --- a/app/test/features/artifacts/ui/artifact_viewer_page_test.dart +++ b/app/test/features/artifacts/ui/artifact_viewer_page_test.dart @@ -4,6 +4,7 @@ import 'dart:typed_data'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_body.dart'; import 'package:pipelines_app/features/artifacts/ui/artifact_video_player.dart'; @@ -616,4 +617,37 @@ void main() { expect(rect.width, greaterThan(0), reason: label); } }); + + testWidgets('Escape closes the viewer back to the gallery', (tester) async { + await tester.pumpWidget( + MaterialApp( + home: ArtifactGalleryPage( + steps: [ + step( + stage: 'review', + visit: 1, + artifacts: [ + artifact( + 'shot.png', + url: '/artifacts/1/1/shot.png', + contentType: 'image/png', + sizeBytes: 1024, + ), + ], + ), + ], + configuredEndpoint: _endpoint, + fetch: (_) async => ArtifactFetchResult(status: 200, bytes: _png), + ), + ), + ); + await tester.pumpAndSettle(); + await tester.tap(find.text('shot.png')); + await tester.pumpAndSettle(); + expect(find.byType(ArtifactViewerPage), findsOneWidget); + + await tester.sendKeyEvent(LogicalKeyboardKey.escape); + await tester.pumpAndSettle(); + expect(find.byType(ArtifactViewerPage), findsNothing); + }); }