Add global keyboard shortcuts cheatsheet
Expose the existing shortcut help as a global Ctrl+?/Cmd+? cheatsheet while preserving Ctrl+/ search behavior. Register the current shortcuts and cover composer, terminal, layout, and close interactions with focused tests.
This commit is contained in:
@@ -0,0 +1,168 @@
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/shell/shell_cheatsheet_shortcut.dart';
|
||||
import 'package:pipelines_app/shell/shell_list_shortcuts.dart';
|
||||
|
||||
class _Held extends HardwareKeyboard {
|
||||
_Held({
|
||||
this.control = false,
|
||||
this.meta = false,
|
||||
this.shift = false,
|
||||
this.alt = false,
|
||||
});
|
||||
|
||||
final bool control;
|
||||
final bool meta;
|
||||
final bool shift;
|
||||
final bool alt;
|
||||
|
||||
@override
|
||||
bool get isControlPressed => control;
|
||||
@override
|
||||
bool get isMetaPressed => meta;
|
||||
@override
|
||||
bool get isShiftPressed => shift;
|
||||
@override
|
||||
bool get isAltPressed => alt;
|
||||
}
|
||||
|
||||
KeyDownEvent _down(LogicalKeyboardKey key, {String? character}) => KeyDownEvent(
|
||||
physicalKey: PhysicalKeyboardKey.slash,
|
||||
logicalKey: key,
|
||||
character: character,
|
||||
timeStamp: Duration.zero,
|
||||
);
|
||||
|
||||
void main() {
|
||||
test('Ctrl+? matches the typed question mark on US and other layouts', () {
|
||||
const linux = TargetPlatform.linux;
|
||||
// US layout: Shift+/ arrives as the slash key with Shift held.
|
||||
expect(
|
||||
shellCheatsheetShortcut(
|
||||
_down(LogicalKeyboardKey.slash, character: '?'),
|
||||
_Held(control: true, shift: true),
|
||||
platform: linux,
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
// A layout whose '?' is its own logical key, with or without Shift.
|
||||
expect(
|
||||
shellCheatsheetShortcut(
|
||||
_down(LogicalKeyboardKey.question, character: '?'),
|
||||
_Held(control: true),
|
||||
platform: linux,
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
expect(
|
||||
shellCheatsheetShortcut(
|
||||
_down(LogicalKeyboardKey.question),
|
||||
_Held(control: true, shift: true),
|
||||
platform: linux,
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
|
||||
test('Ctrl+/ without Shift is Search and never the cheatsheet', () {
|
||||
final slash = _down(LogicalKeyboardKey.slash, character: '/');
|
||||
expect(
|
||||
shellCheatsheetShortcut(
|
||||
slash,
|
||||
_Held(control: true),
|
||||
platform: TargetPlatform.linux,
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
expect(
|
||||
shellSearchShortcut(
|
||||
slash,
|
||||
_Held(control: true),
|
||||
platform: TargetPlatform.linux,
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
|
||||
test('Ctrl+Shift+/ does not open Search', () {
|
||||
final shiftedSlash = _down(LogicalKeyboardKey.slash, character: '?');
|
||||
expect(
|
||||
shellSearchShortcut(
|
||||
shiftedSlash,
|
||||
_Held(control: true, shift: true),
|
||||
platform: TargetPlatform.linux,
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
expect(
|
||||
shellSearchShortcut(
|
||||
shiftedSlash,
|
||||
_Held(control: true, shift: true),
|
||||
platform: TargetPlatform.macOS,
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
|
||||
test('Alt, Cmd off macOS, and key releases do not match', () {
|
||||
final question = _down(LogicalKeyboardKey.question, character: '?');
|
||||
expect(
|
||||
shellCheatsheetShortcut(
|
||||
question,
|
||||
_Held(control: true, alt: true),
|
||||
platform: TargetPlatform.linux,
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
expect(
|
||||
shellCheatsheetShortcut(
|
||||
question,
|
||||
_Held(meta: true),
|
||||
platform: TargetPlatform.linux,
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
expect(
|
||||
shellCheatsheetShortcut(
|
||||
const KeyUpEvent(
|
||||
physicalKey: PhysicalKeyboardKey.slash,
|
||||
logicalKey: LogicalKeyboardKey.question,
|
||||
timeStamp: Duration.zero,
|
||||
),
|
||||
_Held(control: true),
|
||||
platform: TargetPlatform.linux,
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
expect(
|
||||
shellCheatsheetShortcut(
|
||||
_down(LogicalKeyboardKey.keyA),
|
||||
_Held(control: true),
|
||||
platform: TargetPlatform.linux,
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
|
||||
test('macOS accepts Cmd or Ctrl, as Search does', () {
|
||||
final question = _down(LogicalKeyboardKey.question, character: '?');
|
||||
expect(
|
||||
shellCheatsheetShortcut(
|
||||
question,
|
||||
_Held(meta: true),
|
||||
platform: TargetPlatform.macOS,
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
expect(
|
||||
shellCheatsheetShortcut(
|
||||
question,
|
||||
_Held(control: true),
|
||||
platform: TargetPlatform.macOS,
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
expect(shellCheatsheetShortcutLabel(TargetPlatform.macOS), 'Cmd+?, Ctrl+?');
|
||||
expect(shellCheatsheetShortcutLabel(TargetPlatform.windows), 'Ctrl+?');
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user