Make Search Escape restore input then previous tab

This commit is contained in:
2026-11-06 19:10:47 +00:00
parent 1106adbce2
commit 1ee7960925
5 changed files with 279 additions and 4 deletions
+31
View File
@@ -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);