Add Ctrl+A Runs and Pipelines shortcut
Provide a platform-independent destination shortcut that preserves Ctrl+A for text fields and the terminal. Document the shortcut in help and cover navigation and focus exceptions with regression tests.
This commit is contained in:
@@ -5,6 +5,7 @@ import '../chat/workspace/chat_float_shortcut.dart';
|
||||
import '../terminal/terminal_shortcuts.dart';
|
||||
import '../../shell/windows/window_shortcuts.dart';
|
||||
import '../../shell/shell_chat_shortcut.dart';
|
||||
import '../../shell/shell_runs_pipelines_shortcut.dart';
|
||||
import '../../shell/shell_search_shortcut_labels.dart';
|
||||
|
||||
/// A shortcut entry shown in the in-app help. Keeping these entries together
|
||||
@@ -61,6 +62,12 @@ class KeyboardShortcutRegistry {
|
||||
? 'Shows the open chat and focuses its message input. The browser may reserve Ctrl+K.'
|
||||
: 'Shows the open chat and focuses its message input. In the terminal Ctrl+K stays kill-line; Alt+K still opens Chat.',
|
||||
),
|
||||
const KeyboardShortcutEntry(
|
||||
action: 'Switch between Runs and Pipelines',
|
||||
keys: shellRunsPipelinesShortcutLabel,
|
||||
caveat:
|
||||
'Goes to Runs from other destinations and to Pipelines from Runs. In a text field or the terminal Ctrl+A keeps its own meaning.',
|
||||
),
|
||||
KeyboardShortcutEntry(
|
||||
action: 'Toggle Center Stage',
|
||||
keys:
|
||||
|
||||
@@ -11,6 +11,7 @@ import 'list_pane_widths.dart';
|
||||
import 'shell_bar.dart';
|
||||
import 'shell_chat_shortcut.dart';
|
||||
import 'shell_list_shortcuts.dart';
|
||||
import 'shell_runs_pipelines_shortcut.dart';
|
||||
import 'shell_search_shortcut_labels.dart';
|
||||
import 'tab_history.dart';
|
||||
import '../ui/input/keyboard_owner.dart';
|
||||
@@ -274,8 +275,9 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
}
|
||||
|
||||
/// App-wide search and conversation-list selection are handled before text
|
||||
/// fields. Split-pane navigation belongs to the chat workspace; tab changes
|
||||
/// have no global keyboard chord.
|
||||
/// fields. Split-pane navigation belongs to the chat workspace. Ctrl+A
|
||||
/// bounces between Runs and Pipelines, but leaves text fields and the
|
||||
/// terminal their own Ctrl+A (select all, line start).
|
||||
bool _handleDestinationKeyEvent(KeyEvent event) {
|
||||
final keyboard = HardwareKeyboard.instance;
|
||||
// Ctrl+K is the terminal's kill-line while the terminal has the keyboard;
|
||||
@@ -285,6 +287,13 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
if (event is KeyDownEvent) _openChat();
|
||||
return true;
|
||||
}
|
||||
if (shellRunsPipelinesShortcut(event, keyboard)) {
|
||||
if (primaryFocusTakesTyping()) return false;
|
||||
if (event is KeyDownEvent) {
|
||||
_select(shellRunsPipelinesTarget(_selected));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// A terminal keeps its keys (Escape, Ctrl+/, Ctrl+digits).
|
||||
if (primaryFocusIsTypingSurface()) return false;
|
||||
if (_selected == AppDestination.search &&
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'destination.dart';
|
||||
|
||||
/// The chord that bounces between Runs and Pipelines, as the help page reads
|
||||
/// it. It is the same on every platform.
|
||||
const shellRunsPipelinesShortcutLabel = 'Ctrl+A';
|
||||
|
||||
/// Whether [event] is Ctrl+A. Only Ctrl counts: Alt, Shift, Cmd and chords
|
||||
/// with both Ctrl and Alt are not the shortcut. Repeats of a held chord match
|
||||
/// as well, so the caller can swallow them; only its first press acts.
|
||||
bool shellRunsPipelinesShortcut(KeyEvent event, HardwareKeyboard keyboard) {
|
||||
if (event is KeyUpEvent ||
|
||||
keyboard.isAltPressed ||
|
||||
keyboard.isShiftPressed ||
|
||||
keyboard.isMetaPressed ||
|
||||
!keyboard.isControlPressed) {
|
||||
return false;
|
||||
}
|
||||
return event.logicalKey == LogicalKeyboardKey.keyA;
|
||||
}
|
||||
|
||||
/// The destination Ctrl+A goes to from [current]: Pipelines from Runs, and
|
||||
/// Runs from every other destination (Pipelines included).
|
||||
AppDestination shellRunsPipelinesTarget(AppDestination current) =>
|
||||
current == AppDestination.runs
|
||||
? AppDestination.pipelines
|
||||
: AppDestination.runs;
|
||||
@@ -0,0 +1,37 @@
|
||||
# Ctrl+A toggles Runs and Pipelines
|
||||
|
||||
Stage 01-implement (artifact 401). Not committed.
|
||||
|
||||
## Behaviour
|
||||
- Ctrl+A (the same chord on every platform) moves the shell between destinations:
|
||||
- from Runs, to Pipelines;
|
||||
- from Pipelines, to Runs;
|
||||
- from any other destination (Chat, Search, Settings), to Runs.
|
||||
- It is matched like Ctrl+K in `shell/adaptive_shell.dart`: logical key A with Ctrl alone. Alt, Shift, Cmd, Ctrl+Alt, and key-up events do not match. Repeats of a held chord are swallowed; only the first key-down acts.
|
||||
- It does not act while a text field (`primaryFocusTakesTyping`) or a `TypingSurface` such as the terminal has focus. The handler returns false, so the field or terminal keeps Ctrl+A (select all, line start).
|
||||
- The switch goes through the shell's normal `_select`, so a controlled shell (`onDestinationSelected`) receives the destination.
|
||||
|
||||
## Changed paths
|
||||
- `app/lib/shell/shell_runs_pipelines_shortcut.dart` (new): `shellRunsPipelinesShortcut` (matcher), `shellRunsPipelinesTarget` (destination rule), `shellRunsPipelinesShortcutLabel` (`'Ctrl+A'`).
|
||||
- `app/lib/shell/adaptive_shell.dart`: one branch in `_handleDestinationKeyEvent`, after the Ctrl+K branch and before the typing-surface check; updated doc comment.
|
||||
- `app/lib/features/settings/keyboard_shortcuts_registry.dart`: "Switch between Runs and Pipelines" help entry, `Ctrl+A` on every platform, with a caveat about text fields and the terminal.
|
||||
- `app/test/shell/runs_pipelines_shortcut_test.dart` (new): matcher, destination rule, Chat→Runs→Pipelines→Runs sequence, text-field exception, terminal exception.
|
||||
- `app/test/features/settings/keyboard_shortcuts_help_test.dart`: help entry test over every `TargetPlatform` value.
|
||||
|
||||
## Focused results
|
||||
- `tool/memwatch/full.sh 'test/shell/runs_pipelines_shortcut_test.dart test/features/settings/keyboard_shortcuts_help_test.dart test/shell/shell_chat_shortcut_test.dart test/shell/destination_shortcuts_test.dart'`: PASS, 19 passed, 0 failed, peak 1151 MB, 13s, exit 0.
|
||||
- Mutation check: with the `primaryFocusTakesTyping()` guard removed, `runs_pipelines_shortcut_test.dart` fails (2 failed, including the text-field case). The guard was restored; the file matches the pre-mutation backup.
|
||||
- `tool/analyze.sh` on the changed files: clean, exit 0. Run after the focused tests, sequentially.
|
||||
- No existing test sends Ctrl+A. The `keyA` uses in `chat_shell_terminal_test.dart` and `chat_transcript_selection_test.dart` are plain or Cmd+A, so they are unaffected.
|
||||
|
||||
## Affected states
|
||||
- Shell tabs: Pipelines, Runs, Chat, Search, and Settings (a page of Pipelines).
|
||||
- Text field focused: Ctrl+A goes to the field.
|
||||
- Terminal focused: Ctrl+A goes to the terminal.
|
||||
- Help page: new "Switch between Runs and Pipelines" row.
|
||||
|
||||
## Not covered
|
||||
- No UI capture or device run (ui-review owns that).
|
||||
- The text-field test pins the platform to Android so that Ctrl+A means select all. On Apple platforms Ctrl+A is line start in the field; the field still keeps it, but that case is not tested.
|
||||
- The chat composer is not tested directly; it is a text field, so the same guard applies.
|
||||
- On web, the browser may keep Ctrl+A; the registry caveat does not mention this.
|
||||
@@ -40,6 +40,19 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
test('Runs and Pipelines switch is Ctrl+A on every platform', () {
|
||||
for (final platform in TargetPlatform.values) {
|
||||
final entry = KeyboardShortcutRegistry(platform: platform, web: false)
|
||||
.entries
|
||||
.firstWhere(
|
||||
(entry) => entry.action == 'Switch between Runs and Pipelines',
|
||||
);
|
||||
expect(entry.keys, 'Ctrl+A', reason: platform.name);
|
||||
expect(entry.caveat, contains('Pipelines'));
|
||||
expect(entry.caveat, contains('text field'));
|
||||
}
|
||||
});
|
||||
|
||||
test('uses the shell primary modifier rule on iOS', () {
|
||||
final entries = const KeyboardShortcutRegistry(
|
||||
platform: TargetPlatform.iOS,
|
||||
|
||||
@@ -0,0 +1,208 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/shell/adaptive_shell.dart';
|
||||
import 'package:pipelines_app/shell/destination.dart';
|
||||
import 'package:pipelines_app/shell/shell_runs_pipelines_shortcut.dart';
|
||||
import 'package:pipelines_app/ui/input/keyboard_owner.dart';
|
||||
|
||||
const _a = KeyDownEvent(
|
||||
physicalKey: PhysicalKeyboardKey.keyA,
|
||||
logicalKey: LogicalKeyboardKey.keyA,
|
||||
timeStamp: Duration.zero,
|
||||
);
|
||||
|
||||
void main() {
|
||||
test('Ctrl+A matches only with Ctrl alone', () {
|
||||
bool chord(Set<LogicalKeyboardKey> held, [KeyEvent event = _a]) =>
|
||||
shellRunsPipelinesShortcut(event, _FakeKeyboard(held));
|
||||
expect(chord({}), isFalse);
|
||||
expect(chord({LogicalKeyboardKey.controlLeft}), isTrue);
|
||||
expect(chord({LogicalKeyboardKey.controlRight}), isTrue);
|
||||
expect(
|
||||
chord({LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.altLeft}),
|
||||
isFalse,
|
||||
);
|
||||
expect(
|
||||
chord({LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.shiftLeft}),
|
||||
isFalse,
|
||||
);
|
||||
expect(
|
||||
chord({LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.metaLeft}),
|
||||
isFalse,
|
||||
);
|
||||
expect(chord({LogicalKeyboardKey.altLeft}), isFalse);
|
||||
expect(chord({LogicalKeyboardKey.metaLeft}), isFalse);
|
||||
expect(
|
||||
shellRunsPipelinesShortcut(
|
||||
const KeyUpEvent(
|
||||
physicalKey: PhysicalKeyboardKey.keyA,
|
||||
logicalKey: LogicalKeyboardKey.keyA,
|
||||
timeStamp: Duration.zero,
|
||||
),
|
||||
_FakeKeyboard({LogicalKeyboardKey.controlLeft}),
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
|
||||
test('Runs goes to Pipelines; every other destination goes to Runs', () {
|
||||
expect(
|
||||
shellRunsPipelinesTarget(AppDestination.runs),
|
||||
AppDestination.pipelines,
|
||||
);
|
||||
expect(
|
||||
shellRunsPipelinesTarget(AppDestination.pipelines),
|
||||
AppDestination.runs,
|
||||
);
|
||||
expect(shellRunsPipelinesTarget(AppDestination.chat), AppDestination.runs);
|
||||
expect(
|
||||
shellRunsPipelinesTarget(AppDestination.search),
|
||||
AppDestination.runs,
|
||||
);
|
||||
expect(
|
||||
shellRunsPipelinesTarget(AppDestination.settings),
|
||||
AppDestination.runs,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Ctrl+A bounces Chat, Runs, Pipelines, Runs', (tester) async {
|
||||
await _onAndroid(() async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: AdaptiveShell(
|
||||
destinationBodies: {
|
||||
for (final destination in shellTabDestinations)
|
||||
destination: (_) => Text('${destination.name} body'),
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(find.text('pipelines body'), isOnstage);
|
||||
|
||||
Future<void> pressCtrl(LogicalKeyboardKey key) async {
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.sendKeyEvent(key);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
// Reach Chat first with Ctrl+K, then start the Ctrl+A sequence.
|
||||
await pressCtrl(LogicalKeyboardKey.keyK);
|
||||
expect(find.text('chat body'), isOnstage);
|
||||
expect(find.text('pipelines body'), findsNothing);
|
||||
|
||||
await pressCtrl(LogicalKeyboardKey.keyA);
|
||||
expect(find.text('runs body'), isOnstage);
|
||||
expect(find.text('chat body'), findsNothing);
|
||||
|
||||
await pressCtrl(LogicalKeyboardKey.keyA);
|
||||
expect(find.text('pipelines body'), isOnstage);
|
||||
expect(find.text('runs body'), findsNothing);
|
||||
|
||||
await pressCtrl(LogicalKeyboardKey.keyA);
|
||||
expect(find.text('runs body'), isOnstage);
|
||||
expect(find.text('pipelines body'), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('Ctrl+A is left to a focused text field', (tester) async {
|
||||
await _onAndroid(() async {
|
||||
final field = TextEditingController(text: 'draft message');
|
||||
final focus = FocusNode();
|
||||
addTearDown(field.dispose);
|
||||
addTearDown(focus.dispose);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: AdaptiveShell(
|
||||
destinationBodies: {
|
||||
AppDestination.pipelines: (_) =>
|
||||
TextField(controller: field, focusNode: focus),
|
||||
AppDestination.runs: (_) => const Text('runs body'),
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
focus.requestFocus();
|
||||
await tester.pump();
|
||||
expect(focus.hasPrimaryFocus, isTrue);
|
||||
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyA);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Destination unchanged; the field took the chord (select all on this
|
||||
// platform), so the text is still there and fully selected.
|
||||
expect(find.text('runs body'), findsNothing);
|
||||
expect(field.text, 'draft message');
|
||||
expect(field.selection.baseOffset, 0);
|
||||
expect(field.selection.extentOffset, field.text.length);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('Ctrl+A is left to the terminal while it has focus', (
|
||||
tester,
|
||||
) async {
|
||||
await _onAndroid(() async {
|
||||
final terminal = FocusNode();
|
||||
addTearDown(terminal.dispose);
|
||||
final received = <KeyEvent>[];
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: AdaptiveShell(
|
||||
destinationBodies: {
|
||||
AppDestination.pipelines: (_) => TypingSurface(
|
||||
child: Focus(
|
||||
focusNode: terminal,
|
||||
onKeyEvent: (node, event) {
|
||||
if (event.logicalKey == LogicalKeyboardKey.keyA) {
|
||||
received.add(event);
|
||||
}
|
||||
return KeyEventResult.ignored;
|
||||
},
|
||||
child: const Text('terminal'),
|
||||
),
|
||||
),
|
||||
AppDestination.runs: (_) => const Text('runs body'),
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
terminal.requestFocus();
|
||||
await tester.pump();
|
||||
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyA);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('runs body'), findsNothing);
|
||||
expect(find.text('terminal'), isOnstage);
|
||||
expect(received.whereType<KeyDownEvent>(), hasLength(1));
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// Runs [body] with the platform pinned to Android, so Ctrl+A in a text field
|
||||
/// means select all everywhere. flutter_test requires the debug override to be
|
||||
/// cleared before the test body returns, hence the `finally`.
|
||||
Future<void> _onAndroid(Future<void> Function() body) async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.android;
|
||||
try {
|
||||
await body();
|
||||
} finally {
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
}
|
||||
}
|
||||
|
||||
class _FakeKeyboard extends HardwareKeyboard {
|
||||
_FakeKeyboard(this.pressed);
|
||||
final Set<LogicalKeyboardKey> pressed;
|
||||
@override
|
||||
bool isLogicalKeyPressed(LogicalKeyboardKey key) => pressed.contains(key);
|
||||
}
|
||||
Reference in New Issue
Block a user