Make Search Escape restore input then previous tab
This commit is contained in:
@@ -282,6 +282,16 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
/// have no global keyboard chord.
|
||||
bool _handleDestinationKeyEvent(KeyEvent event) {
|
||||
final keyboard = HardwareKeyboard.instance;
|
||||
if (_selected == AppDestination.search &&
|
||||
event is KeyDownEvent &&
|
||||
event.logicalKey == LogicalKeyboardKey.escape &&
|
||||
!keyboard.isControlPressed &&
|
||||
!keyboard.isMetaPressed &&
|
||||
!keyboard.isShiftPressed &&
|
||||
!keyboard.isAltPressed &&
|
||||
_searchEscape()) {
|
||||
return true;
|
||||
}
|
||||
if (shellSearchShortcut(event, keyboard)) {
|
||||
_select(AppDestination.search);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
@@ -297,6 +307,27 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
return _bar.lists.open(AppDestination.chat, listIndex);
|
||||
}
|
||||
|
||||
/// A popup or nested viewer owns Escape before the underlying Search tab.
|
||||
bool _searchEscape() {
|
||||
final route = ModalRoute.of(context);
|
||||
if (route != null && !route.isCurrent) return false;
|
||||
final focusedContext = FocusManager.instance.primaryFocus?.context;
|
||||
final focusedRoute = focusedContext == null
|
||||
? null
|
||||
: ModalRoute.of(focusedContext);
|
||||
if (focusedRoute != null && route != null && focusedRoute != route) {
|
||||
return false;
|
||||
}
|
||||
if (!_bar.searchFocus.available) return false;
|
||||
if (!_bar.searchFocus.focused) {
|
||||
_bar.searchFocus.request();
|
||||
return true;
|
||||
}
|
||||
if (_history.isEmpty) return false;
|
||||
_back(page: false);
|
||||
return true;
|
||||
}
|
||||
|
||||
List<FloatingDestinationItem> _destinationItems() =>
|
||||
shellTabDestinations.map((destination) {
|
||||
final item = destinationDetails(destination);
|
||||
|
||||
@@ -8,17 +8,22 @@ import 'shell_bar.dart';
|
||||
class ShellSearchFocus {
|
||||
Object? _owner;
|
||||
VoidCallback? _focus;
|
||||
bool Function()? _hasFocus;
|
||||
bool get available => _focus != null;
|
||||
bool get focused => _hasFocus?.call() ?? false;
|
||||
void request() => _focus?.call();
|
||||
|
||||
void _set(Object owner, VoidCallback focus) {
|
||||
void _set(Object owner, VoidCallback focus, bool Function() hasFocus) {
|
||||
_owner = owner;
|
||||
_focus = focus;
|
||||
_hasFocus = hasFocus;
|
||||
}
|
||||
|
||||
void _clear(Object owner) {
|
||||
if (_owner != owner) return;
|
||||
_owner = null;
|
||||
_focus = null;
|
||||
_hasFocus = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,9 +31,11 @@ class ShellSearchShortcut extends StatefulWidget {
|
||||
const ShellSearchShortcut({
|
||||
super.key,
|
||||
required this.onFocus,
|
||||
required this.hasFocus,
|
||||
required this.child,
|
||||
});
|
||||
final VoidCallback onFocus;
|
||||
final bool Function() hasFocus;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
@@ -47,7 +54,11 @@ class _ShellSearchShortcutState extends State<ShellSearchShortcut> {
|
||||
_scope?.registry.searchFocus._clear(_owner);
|
||||
_scope = scope;
|
||||
if (scope?.destination == AppDestination.search) {
|
||||
scope!.registry.searchFocus._set(_owner, () => widget.onFocus());
|
||||
scope!.registry.searchFocus._set(
|
||||
_owner,
|
||||
() => widget.onFocus(),
|
||||
() => widget.hasFocus(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user