From 1495dd0f9e07939a4f13b97ac8605efe62e21134 Mon Sep 17 00:00:00 2001 From: Elias Bonnici Date: Thu, 21 Mar 2024 12:22:46 +0100 Subject: [PATCH] Use one global key for search field --- lib/app/shortcuts.dart | 18 +++++------------- lib/app/views/keys.dart | 2 ++ lib/fido/keys.dart | 3 --- lib/fido/views/passkeys_screen.dart | 4 ++-- lib/oath/keys.dart | 3 --- lib/oath/views/oath_screen.dart | 3 ++- 6 files changed, 11 insertions(+), 22 deletions(-) diff --git a/lib/app/shortcuts.dart b/lib/app/shortcuts.dart index 0cbeb409..634baf0f 100755 --- a/lib/app/shortcuts.dart +++ b/lib/app/shortcuts.dart @@ -24,8 +24,6 @@ import 'package:window_manager/window_manager.dart'; import '../about_page.dart'; import '../core/state.dart'; import '../desktop/state.dart'; -import '../fido/keys.dart'; -import '../oath/keys.dart'; import 'message.dart'; import 'models.dart'; import 'state.dart'; @@ -131,17 +129,11 @@ class GlobalShortcuts extends ConsumerWidget { return null; }), SearchIntent: CallbackAction(onInvoke: (intent) { - // If the OATH or passkeys view doesn't have focus, but is shown, find and select the search bar. - final accountsSearchContext = searchAccountsField.currentContext; - if (accountsSearchContext != null) { - if (!Navigator.of(accountsSearchContext).canPop()) { - return Actions.maybeInvoke(accountsSearchContext, intent); - } - } - final passkeysSearchContext = searchPasskeysField.currentContext; - if (passkeysSearchContext != null) { - if (!Navigator.of(passkeysSearchContext).canPop()) { - return Actions.maybeInvoke(passkeysSearchContext, intent); + // If the view doesn't have focus, but is shown, find and select the search bar. + final searchContext = searchField.currentContext; + if (searchContext != null) { + if (!Navigator.of(searchContext).canPop()) { + return Actions.maybeInvoke(searchContext, intent); } } return null; diff --git a/lib/app/views/keys.dart b/lib/app/views/keys.dart index bb0e5079..399edd1d 100644 --- a/lib/app/views/keys.dart +++ b/lib/app/views/keys.dart @@ -18,6 +18,8 @@ import 'package:flutter/material.dart'; // global keys final scaffoldGlobalKey = GlobalKey(); +// This is global so we can access it from the global Ctrl+F shortcut. +final searchField = GlobalKey(); const _prefix = 'app.keys'; const deviceInfoListTile = Key('$_prefix.device_info_list_tile'); diff --git a/lib/fido/keys.dart b/lib/fido/keys.dart index c4a54746..ab6a7e11 100644 --- a/lib/fido/keys.dart +++ b/lib/fido/keys.dart @@ -21,9 +21,6 @@ const _keyAction = '$_prefix.actions'; const _credentialAction = '$_prefix.credential.actions'; const _fingerprintAction = '$_prefix.fingerprint.actions'; -// This is global so we can access it from the global Ctrl+F shortcut. -final searchPasskeysField = GlobalKey(); - // Key actions const managePinAction = Key('$_keyAction.manage_pin'); const addFingerprintAction = Key('$_keyAction.add_fingerprint'); diff --git a/lib/fido/views/passkeys_screen.dart b/lib/fido/views/passkeys_screen.dart index 1467ba86..f42cc98b 100644 --- a/lib/fido/views/passkeys_screen.dart +++ b/lib/fido/views/passkeys_screen.dart @@ -30,6 +30,7 @@ import '../../app/views/action_list.dart'; import '../../app/views/app_failure_page.dart'; import '../../app/views/app_list_item.dart'; import '../../app/views/app_page.dart'; +import '../../app/views/keys.dart'; import '../../app/views/message_page.dart'; import '../../app/views/message_page_not_initialized.dart'; import '../../core/state.dart'; @@ -39,7 +40,6 @@ import '../../widgets/app_input_decoration.dart'; import '../../widgets/app_text_form_field.dart'; import '../../widgets/list_title.dart'; import '../features.dart' as features; -import '../keys.dart' as keys; import '../models.dart'; import '../state.dart'; import 'actions.dart'; @@ -367,7 +367,7 @@ class _FidoUnlockedPageState extends ConsumerState<_FidoUnlockedPage> { padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0), child: AppTextFormField( - key: keys.searchPasskeysField, + key: searchField, controller: searchController, focusNode: searchFocus, // Use the default style, but with a smaller font size: diff --git a/lib/oath/keys.dart b/lib/oath/keys.dart index 546de5b6..e1248bfd 100755 --- a/lib/oath/keys.dart +++ b/lib/oath/keys.dart @@ -20,9 +20,6 @@ const _prefix = 'oath.keys'; const _keyAction = '$_prefix.actions'; const _accountAction = '$_prefix.account.actions'; -// This is global so we can access it from the global Ctrl+F shortcut. -final searchAccountsField = GlobalKey(); - // Key actions const setOrManagePasswordAction = Key('$_keyAction.action.set_or_manage_password'); diff --git a/lib/oath/views/oath_screen.dart b/lib/oath/views/oath_screen.dart index ce05bfbd..9c91874d 100755 --- a/lib/oath/views/oath_screen.dart +++ b/lib/oath/views/oath_screen.dart @@ -30,6 +30,7 @@ import '../../app/state.dart'; import '../../app/views/action_list.dart'; import '../../app/views/app_failure_page.dart'; import '../../app/views/app_page.dart'; +import '../../app/views/keys.dart'; import '../../app/views/message_page.dart'; import '../../app/views/message_page_not_initialized.dart'; import '../../core/state.dart'; @@ -377,7 +378,7 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> { padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0), child: AppTextFormField( - key: keys.searchAccountsField, + key: searchField, controller: searchController, focusNode: searchFocus, // Use the default style, but with a smaller font size: