Support Command conversation shortcuts in Mac browsers
This commit is contained in:
@@ -279,7 +279,10 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
/// Ctrl+1…Ctrl+9 open the Nth item of the open tab's list the same way, in
|
||||
/// the list's on-screen order; a page (Settings) has no list.
|
||||
bool _handleDestinationKeyEvent(KeyEvent event) {
|
||||
final listIndex = shellListShortcutIndex(event, HardwareKeyboard.instance);
|
||||
final listIndex = shellListShortcutIndex(
|
||||
event,
|
||||
HardwareKeyboard.instance,
|
||||
);
|
||||
if (listIndex != null) {
|
||||
if (!shellTabDestinations.contains(_selected)) return false;
|
||||
return _bar.lists.open(_selected, listIndex);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
@@ -5,7 +6,8 @@ import 'destination.dart';
|
||||
import 'shell_bar.dart';
|
||||
|
||||
/// Opens the Nth item of a tab's list: what each tab's list screen published
|
||||
/// for Ctrl+1…Ctrl+9. One opener per tab; the latest mounted list wins.
|
||||
/// for Ctrl+1…Ctrl+9 (also Command on macOS). One opener per tab;
|
||||
/// the latest mounted list wins.
|
||||
class ShellListShortcuts {
|
||||
final Map<AppDestination, (Object, bool Function(int index))> _openers = {};
|
||||
|
||||
@@ -25,15 +27,22 @@ class ShellListShortcuts {
|
||||
}
|
||||
}
|
||||
|
||||
/// The 0-based list index a Ctrl+1…Ctrl+9 key event names, or null for any
|
||||
/// other event. Shift, Alt and Meta must be up, so system and browser chords
|
||||
/// built on the digits are left alone.
|
||||
int? shellListShortcutIndex(KeyEvent event, HardwareKeyboard keyboard) {
|
||||
/// The 0-based list index named by Ctrl+1…9, or Command+1…9 on macOS.
|
||||
/// Extra modifiers and non-digit events pass through.
|
||||
int? shellListShortcutIndex(
|
||||
KeyEvent event,
|
||||
HardwareKeyboard keyboard, {
|
||||
TargetPlatform? platform,
|
||||
}) {
|
||||
final control = keyboard.isControlPressed && !keyboard.isMetaPressed;
|
||||
final command =
|
||||
(platform ?? defaultTargetPlatform) == TargetPlatform.macOS &&
|
||||
keyboard.isMetaPressed &&
|
||||
!keyboard.isControlPressed;
|
||||
if (event is! KeyDownEvent ||
|
||||
!keyboard.isControlPressed ||
|
||||
!(control || command) ||
|
||||
keyboard.isShiftPressed ||
|
||||
keyboard.isAltPressed ||
|
||||
keyboard.isMetaPressed) {
|
||||
keyboard.isAltPressed) {
|
||||
return null;
|
||||
}
|
||||
final index = _digits.indexOf(event.logicalKey);
|
||||
|
||||
Reference in New Issue
Block a user