Reserve global shortcuts for chat selection and search
This commit is contained in:
@@ -273,34 +273,24 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
if (previous != null) _select(previous);
|
||||
}
|
||||
|
||||
/// Handles this before focused text controls can insert or traverse on
|
||||
/// Ctrl+Tab. The handler is scoped to the shell's lifetime, not onboarding.
|
||||
///
|
||||
/// 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.
|
||||
/// 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.
|
||||
bool _handleDestinationKeyEvent(KeyEvent event) {
|
||||
final listIndex = shellListShortcutIndex(
|
||||
event,
|
||||
HardwareKeyboard.instance,
|
||||
);
|
||||
if (listIndex != null) {
|
||||
if (!shellTabDestinations.contains(_selected)) return false;
|
||||
return _bar.lists.open(_selected, listIndex);
|
||||
final keyboard = HardwareKeyboard.instance;
|
||||
if (shellSearchShortcut(event, keyboard)) {
|
||||
_select(AppDestination.search);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted && _selected == AppDestination.search) {
|
||||
_bar.searchFocus.request();
|
||||
}
|
||||
});
|
||||
WidgetsBinding.instance.ensureVisualUpdate();
|
||||
return true;
|
||||
}
|
||||
if (event is! KeyDownEvent ||
|
||||
event.logicalKey != LogicalKeyboardKey.tab ||
|
||||
!HardwareKeyboard.instance.isControlPressed) {
|
||||
return false;
|
||||
}
|
||||
final current = shellTabDestinations.indexOf(shellTabFor(_selected));
|
||||
final direction = HardwareKeyboard.instance.isShiftPressed ? -1 : 1;
|
||||
final next = (current + direction) % shellTabDestinations.length;
|
||||
_select(
|
||||
shellTabDestinations[next < 0
|
||||
? next + shellTabDestinations.length
|
||||
: next],
|
||||
);
|
||||
return true;
|
||||
final listIndex = shellListShortcutIndex(event, keyboard);
|
||||
if (listIndex == null || _selected != AppDestination.chat) return false;
|
||||
return _bar.lists.open(AppDestination.chat, listIndex);
|
||||
}
|
||||
|
||||
List<FloatingDestinationItem> _destinationItems() =>
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'destination.dart';
|
||||
import 'shell_list_shortcuts.dart';
|
||||
import 'shell_search_focus.dart';
|
||||
|
||||
/// What the open screen of a tab puts in the app bar: its title, a Back
|
||||
/// control and its actions. Absent, the bar shows the tab's own name.
|
||||
@@ -66,9 +67,11 @@ class ShellBarRegistry extends ChangeNotifier {
|
||||
final _Notifier _bar = _Notifier();
|
||||
final _Notifier _badgeNotifier = _Notifier();
|
||||
|
||||
/// How each tab's list opens its Nth item (Ctrl+1…Ctrl+9).
|
||||
/// Registered list openers; keyboard shortcuts invoke Chat only.
|
||||
final ShellListShortcuts lists = ShellListShortcuts();
|
||||
|
||||
final ShellSearchFocus searchFocus = ShellSearchFocus();
|
||||
|
||||
/// The destination whose bar is on screen; null treats every destination
|
||||
/// as shown. Bar changes of other destinations are kept without notifying:
|
||||
/// the host rebuilds when it changes the focus.
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'destination.dart';
|
||||
import 'shell_bar.dart';
|
||||
|
||||
/// The mounted Search screen publishes its field focus without clearing query
|
||||
/// state. The shell requests it after switching destinations has settled.
|
||||
class ShellSearchFocus {
|
||||
Object? _owner;
|
||||
VoidCallback? _focus;
|
||||
void request() => _focus?.call();
|
||||
|
||||
void _set(Object owner, VoidCallback focus) {
|
||||
_owner = owner;
|
||||
_focus = focus;
|
||||
}
|
||||
|
||||
void _clear(Object owner) {
|
||||
if (_owner != owner) return;
|
||||
_owner = null;
|
||||
_focus = null;
|
||||
}
|
||||
}
|
||||
|
||||
class ShellSearchShortcut extends StatefulWidget {
|
||||
const ShellSearchShortcut({
|
||||
super.key,
|
||||
required this.onFocus,
|
||||
required this.child,
|
||||
});
|
||||
final VoidCallback onFocus;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
State<ShellSearchShortcut> createState() => _ShellSearchShortcutState();
|
||||
}
|
||||
|
||||
class _ShellSearchShortcutState extends State<ShellSearchShortcut> {
|
||||
final _owner = Object();
|
||||
ShellBarScope? _scope;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
final scope = ShellBarScope.maybeOf(context);
|
||||
if (scope == _scope) return;
|
||||
_scope?.registry.searchFocus._clear(_owner);
|
||||
_scope = scope;
|
||||
if (scope?.destination == AppDestination.search) {
|
||||
scope!.registry.searchFocus._set(_owner, () => widget.onFocus());
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_scope?.registry.searchFocus._clear(_owner);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => widget.child;
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import 'destination.dart';
|
||||
|
||||
/// The tabs the operator left, most recent first, for the system Back.
|
||||
///
|
||||
/// Every tab change (a tap, Ctrl+Tab, a search result or notification opening
|
||||
/// Every tab change (a tap, a search result or notification opening
|
||||
/// another tab) goes through [record]: the tab being left moves to the top
|
||||
/// and the tab being opened leaves the stack, so each tab appears at most once
|
||||
/// and the current tab is never in it. A page that belongs to a tab
|
||||
|
||||
Reference in New Issue
Block a user