Redesign the keyboard shortcuts cheatsheet with fuzzy search
One fixed-size list of grouped cards: actions and notes on the leading side, keys drawn as keycaps in an aligned trailing column that never ends a line on a joining word. A search field, focused when Ctrl+? opens it, filters fuzzily by action and keys (exactly by group and note) and highlights the matched letters.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/settings/keyboard_shortcut_keys.dart';
|
||||
import 'package:pipelines_app/features/settings/keyboard_shortcuts_help.dart';
|
||||
import 'package:pipelines_app/features/settings/keyboard_shortcuts_registry.dart';
|
||||
|
||||
@@ -118,47 +119,14 @@ void main() {
|
||||
expect(actions, isNot(contains('Move between terminal tabs')));
|
||||
});
|
||||
|
||||
testWidgets('wide help splits groups into two columns', (tester) async {
|
||||
testWidgets('groups stack in one column with their keys right-aligned', (
|
||||
tester,
|
||||
) async {
|
||||
const registry = KeyboardShortcutRegistry(
|
||||
platform: TargetPlatform.windows,
|
||||
web: false,
|
||||
);
|
||||
tester.view.physicalSize = const Size(900, 1400);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
// The desktop dialog scrolls its content; mirror that here.
|
||||
body: SingleChildScrollView(
|
||||
child: Center(
|
||||
child: SizedBox(
|
||||
width: 640,
|
||||
child: KeyboardShortcutsHelp(registry: registry),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final navigation = tester.getTopLeft(find.text('Navigation'));
|
||||
final chat = tester.getTopLeft(find.text('Chat'));
|
||||
final windows = tester.getTopLeft(find.text('Windows'));
|
||||
final lists = tester.getTopLeft(find.text('Lists'));
|
||||
expect(chat.dx, greaterThan(navigation.dx));
|
||||
expect(lists.dx, greaterThan(navigation.dx));
|
||||
expect(windows.dx, navigation.dx);
|
||||
expect(windows.dy, greaterThan(navigation.dy));
|
||||
});
|
||||
|
||||
testWidgets('narrow help stacks groups in one column', (tester) async {
|
||||
const registry = KeyboardShortcutRegistry(
|
||||
platform: TargetPlatform.iOS,
|
||||
web: false,
|
||||
);
|
||||
tester.view.physicalSize = const Size(360, 720);
|
||||
tester.view.physicalSize = const Size(720, 2400);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
@@ -172,5 +140,13 @@ void main() {
|
||||
final chat = tester.getTopLeft(find.text('Chat'));
|
||||
expect(chat.dx, navigation.dx);
|
||||
expect(chat.dy, greaterThan(navigation.dy));
|
||||
// Every row's keys end at the same trailing edge.
|
||||
final ends = {
|
||||
for (final keys in tester.widgetList<ShortcutKeys>(
|
||||
find.byType(ShortcutKeys),
|
||||
))
|
||||
tester.getTopRight(find.byWidget(keys)).dx,
|
||||
};
|
||||
expect(ends, hasLength(1));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/settings/keyboard_shortcut_keys.dart';
|
||||
import 'package:pipelines_app/features/settings/keyboard_shortcuts_filter.dart';
|
||||
import 'package:pipelines_app/features/settings/keyboard_shortcuts_registry.dart';
|
||||
|
||||
void main() {
|
||||
const registry = KeyboardShortcutRegistry(
|
||||
platform: TargetPlatform.linux,
|
||||
web: false,
|
||||
);
|
||||
List<String> actions(String query) => [
|
||||
for (final match in filterShortcuts(registry.entries, query))
|
||||
match.entry.action,
|
||||
];
|
||||
|
||||
test('an empty query keeps every entry in registry order', () {
|
||||
expect(actions(' '), [for (final e in registry.entries) e.action]);
|
||||
});
|
||||
|
||||
test('a subsequence of the action matches and ranks first', () {
|
||||
final found = actions('flt');
|
||||
expect(found.first, contains('floating'));
|
||||
});
|
||||
|
||||
test('scattered letters in a long note do not match', () {
|
||||
// `float` occurs only as scattered letters in other entries' notes.
|
||||
expect(actions('float'), everyElement(contains('floating')));
|
||||
});
|
||||
|
||||
test('keys are searchable with or without the plus', () {
|
||||
expect(actions('ctrl k'), contains('Open Chat'));
|
||||
expect(actions('ctrlk'), contains('Open Chat'));
|
||||
});
|
||||
|
||||
test('every word must match', () {
|
||||
expect(actions('terminal paste'), ['Paste into the terminal']);
|
||||
expect(actions('terminal zzqx'), isEmpty);
|
||||
});
|
||||
|
||||
test('the action positions matched are reported for highlighting', () {
|
||||
final match = filterShortcuts(
|
||||
registry.entries,
|
||||
'open chat',
|
||||
).firstWhere((m) => m.entry.action == 'Open Chat');
|
||||
expect(match.actionMatches, containsAll([0, 1, 2, 3, 5, 6, 7, 8]));
|
||||
});
|
||||
|
||||
test('chords split on commas and keys on plus signs', () {
|
||||
expect(shortcutChords('Alt+K, Ctrl+K'), [
|
||||
['Alt', 'K'],
|
||||
['Ctrl', 'K'],
|
||||
]);
|
||||
expect(shortcutChords('Esc, Esc'), [
|
||||
['Esc'],
|
||||
['Esc'],
|
||||
]);
|
||||
expect(shortcutChords('Ctrl+1…9'), [
|
||||
['Ctrl', '1…9'],
|
||||
]);
|
||||
});
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/settings/keyboard_shortcut_keys.dart';
|
||||
import 'package:pipelines_app/features/settings/keyboard_shortcuts_help.dart';
|
||||
import 'package:pipelines_app/features/settings/keyboard_shortcuts_registry.dart';
|
||||
|
||||
@@ -76,20 +77,45 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('help is readable and keyboard traversable', (tester) async {
|
||||
Future<void> pumpHelp(
|
||||
WidgetTester tester, {
|
||||
bool focusSearch = false,
|
||||
Size size = const Size(720, 900),
|
||||
}) async {
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: SingleChildScrollView(
|
||||
child: KeyboardShortcutsHelp(registry: registry),
|
||||
body: KeyboardShortcutsHelp(
|
||||
registry: registry,
|
||||
focusSearch: focusSearch,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
Finder search() => find.byKey(const Key('keyboard-shortcuts-search'));
|
||||
|
||||
testWidgets('help is readable and keyboard traversable', (tester) async {
|
||||
// Tall enough that the lazily built list lays out every group.
|
||||
await pumpHelp(tester, size: const Size(720, 4000));
|
||||
|
||||
expect(find.text('Keyboard shortcuts'), findsOneWidget);
|
||||
expect(find.text('Show or hide floating chats'), findsOneWidget);
|
||||
expect(find.text('Option+Y, Ctrl+Y, Cmd+Y'), findsOneWidget);
|
||||
// Keys are drawn as keycaps, one per key of each chord.
|
||||
expect(find.text('Option'), findsWidgets);
|
||||
expect(find.byType(ShortcutKeycap), findsWidgets);
|
||||
expect(
|
||||
find.bySemanticsLabel(
|
||||
RegExp(r'^Show or hide floating chats: Option\+Y, Ctrl\+Y, Cmd\+Y'),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
tester.getSemantics(find.bySemanticsLabel('Keyboard shortcuts help')),
|
||||
matchesSemantics(
|
||||
@@ -103,20 +129,61 @@ void main() {
|
||||
expect(find.byTooltip('Close keyboard shortcuts'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('narrow help content scrolls', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MediaQuery(
|
||||
data: const MediaQueryData(
|
||||
size: Size(400, 640),
|
||||
textScaler: TextScaler.linear(2),
|
||||
),
|
||||
child: MaterialApp(
|
||||
home: Scaffold(body: KeyboardShortcutsHelp(registry: registry)),
|
||||
),
|
||||
),
|
||||
);
|
||||
testWidgets('the search field is not focused unless asked', (tester) async {
|
||||
await pumpHelp(tester);
|
||||
expect(tester.widget<SearchBar>(search()).focusNode!.hasFocus, isFalse);
|
||||
});
|
||||
|
||||
expect(find.byType(SingleChildScrollView), findsOneWidget);
|
||||
expect(find.text('Keyboard shortcuts'), findsOneWidget);
|
||||
testWidgets('the search field starts focused when asked', (tester) async {
|
||||
await pumpHelp(tester, focusSearch: true);
|
||||
await tester.pump();
|
||||
expect(tester.widget<SearchBar>(search()).focusNode!.hasFocus, isTrue);
|
||||
});
|
||||
|
||||
testWidgets('typing filters fuzzily and highlights the action', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpHelp(tester, focusSearch: true);
|
||||
await tester.enterText(search(), 'flt');
|
||||
await tester.pump();
|
||||
|
||||
expect(find.textContaining('floating', findRichText: true), findsWidgets);
|
||||
expect(find.text('Open Search'), findsNothing);
|
||||
expect(find.text('Leave Search'), findsNothing);
|
||||
// Only the groups that still have a match are shown.
|
||||
expect(find.text('Windows'), findsOneWidget);
|
||||
expect(find.text('Navigation'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('keys can be searched as written', (tester) async {
|
||||
await pumpHelp(tester);
|
||||
await tester.enterText(search(), 'option k');
|
||||
await tester.pump();
|
||||
expect(find.text('Open Chat'), findsOneWidget);
|
||||
expect(find.text('Leave Search'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('no match says so and Clear restores the list', (tester) async {
|
||||
await pumpHelp(tester);
|
||||
await tester.enterText(search(), 'zzqx');
|
||||
await tester.pump();
|
||||
expect(find.text('No shortcuts match “zzqx”'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byTooltip('Clear search'));
|
||||
await tester.pump();
|
||||
expect(find.text('Navigation'), findsOneWidget);
|
||||
expect(find.textContaining('No shortcuts match'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('phone-sized help scrolls its list under a fixed header', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpHelp(tester, size: const Size(400, 640));
|
||||
final list = find.byKey(const Key('keyboard-shortcuts-list'));
|
||||
expect(list, findsOneWidget);
|
||||
final before = tester.getTopLeft(search()).dy;
|
||||
await tester.drag(list, const Offset(0, -400));
|
||||
await tester.pump();
|
||||
expect(tester.getTopLeft(search()).dy, before);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user