Add shell destination keyboard shortcuts

This commit is contained in:
2026-11-01 00:34:54 +00:00
parent 8193626076
commit f422d26e32
2 changed files with 111 additions and 0 deletions
+22
View File
@@ -1,6 +1,7 @@
import '../ui/motion/motion.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../ui/adaptive/segmented_bar.dart';
import '../ui/adaptive/floating_bar_layout.dart';
@@ -50,6 +51,7 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
@override
void dispose() {
HardwareKeyboard.instance.removeHandler(_handleDestinationKeyEvent);
_bar.dispose();
super.dispose();
}
@@ -59,6 +61,7 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
super.initState();
_selected = widget.destination ?? AppDestination.pipelines;
_visited.add(_selected);
HardwareKeyboard.instance.addHandler(_handleDestinationKeyEvent);
}
@override
@@ -214,6 +217,25 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
/// Leaves a page destination (Settings) for the tab it belongs to.
void _closePage() => _select(shellTabFor(_selected));
/// Handles this before focused text controls can insert or traverse on
/// Ctrl+Tab. The handler is scoped to the shell's lifetime, not onboarding.
bool _handleDestinationKeyEvent(KeyEvent event) {
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;
}
List<FloatingDestinationItem> _destinationItems() =>
shellTabDestinations.map((destination) {
final item = destinationDetails(destination);