Reserve global shortcuts for chat selection and search
This commit is contained in:
@@ -5,9 +5,9 @@ import 'package:flutter/widgets.dart';
|
||||
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 (also Command on macOS). One opener per tab;
|
||||
/// the latest mounted list wins.
|
||||
/// List openers registered by destination. The shell invokes only Chat for
|
||||
/// Ctrl+1…Ctrl+9 (also Command on macOS); Pipelines and Runs have no chord.
|
||||
/// One opener per destination; the latest mounted list wins.
|
||||
class ShellListShortcuts {
|
||||
final Map<AppDestination, (Object, bool Function(int index))> _openers = {};
|
||||
|
||||
@@ -34,13 +34,8 @@ int? shellListShortcutIndex(
|
||||
HardwareKeyboard keyboard, {
|
||||
TargetPlatform? platform,
|
||||
}) {
|
||||
final control = keyboard.isControlPressed && !keyboard.isMetaPressed;
|
||||
final command =
|
||||
(platform ?? defaultTargetPlatform) == TargetPlatform.macOS &&
|
||||
keyboard.isMetaPressed &&
|
||||
!keyboard.isControlPressed;
|
||||
if (event is! KeyDownEvent ||
|
||||
!(control || command) ||
|
||||
!shellPrimaryModifier(keyboard, platform: platform) ||
|
||||
keyboard.isShiftPressed ||
|
||||
keyboard.isAltPressed) {
|
||||
return null;
|
||||
@@ -49,6 +44,28 @@ int? shellListShortcutIndex(
|
||||
return index < 0 ? null : index;
|
||||
}
|
||||
|
||||
/// Ctrl on any host, or Command on the actual macOS host. Theme overrides do
|
||||
/// not change keyboard conventions in a browser.
|
||||
bool shellPrimaryModifier(
|
||||
HardwareKeyboard keyboard, {
|
||||
TargetPlatform? platform,
|
||||
}) =>
|
||||
(keyboard.isControlPressed && !keyboard.isMetaPressed) ||
|
||||
((platform ?? defaultTargetPlatform) == TargetPlatform.macOS &&
|
||||
keyboard.isMetaPressed &&
|
||||
!keyboard.isControlPressed);
|
||||
|
||||
bool shellSearchShortcut(
|
||||
KeyEvent event,
|
||||
HardwareKeyboard keyboard, {
|
||||
TargetPlatform? platform,
|
||||
}) =>
|
||||
event is KeyDownEvent &&
|
||||
event.logicalKey == LogicalKeyboardKey.slash &&
|
||||
shellPrimaryModifier(keyboard, platform: platform) &&
|
||||
!keyboard.isAltPressed &&
|
||||
!keyboard.isShiftPressed;
|
||||
|
||||
const _digits = [
|
||||
LogicalKeyboardKey.digit1,
|
||||
LogicalKeyboardKey.digit2,
|
||||
@@ -62,8 +79,8 @@ const _digits = [
|
||||
];
|
||||
|
||||
/// Publishes, while mounted, how its tab's list opens its Nth item, so the
|
||||
/// shell's Ctrl+1…Ctrl+9 open it from anywhere in the tab (also while a text
|
||||
/// field has focus). [onOpenIndex] reads the list at key time, in on-screen
|
||||
/// shell can open an item without coupling to its screen (also while a text
|
||||
/// field has focus). Keyboard dispatch currently invokes only Chat. [onOpenIndex] reads the list at key time, in on-screen
|
||||
/// order, and reports whether an item was opened. Outside a shell it does
|
||||
/// nothing.
|
||||
class ShellListShortcut extends StatefulWidget {
|
||||
|
||||
Reference in New Issue
Block a user