Fix focus issue for Ctrl+F, add Ctrl+W to close.

This commit is contained in:
Dain Nilsson 2023-02-09 13:43:27 +01:00
parent befaa85248
commit 9de315f472
No known key found for this signature in database
GPG Key ID: F04367096FBA95E8
3 changed files with 41 additions and 5 deletions

View File

@ -30,9 +30,8 @@ class YubicoAuthenticatorApp extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
return LogWarningOverlay(
child: Shortcuts(
shortcuts: globalShortcuts,
return registerGlobalShortcuts(
LogWarningOverlay(
child: MaterialApp(
title: 'Yubico Authenticator',
theme: AppTheme.lightTheme,

View File

@ -18,11 +18,18 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:window_manager/window_manager.dart';
import '../oath/keys.dart';
class CopyIntent extends Intent {
const CopyIntent();
}
class CloseIntent extends Intent {
const CloseIntent();
}
class SearchIntent extends Intent {
const SearchIntent();
}
@ -30,7 +37,35 @@ class SearchIntent extends Intent {
final ctrlOrCmd =
Platform.isMacOS ? LogicalKeyboardKey.meta : LogicalKeyboardKey.control;
final globalShortcuts = {
final _globalShortcuts = {
LogicalKeySet(ctrlOrCmd, LogicalKeyboardKey.keyC): const CopyIntent(),
if (Platform.isMacOS)
LogicalKeySet(ctrlOrCmd, LogicalKeyboardKey.keyQ): const CloseIntent(),
LogicalKeySet(ctrlOrCmd, LogicalKeyboardKey.keyW): const CloseIntent(),
LogicalKeySet(ctrlOrCmd, LogicalKeyboardKey.keyF): const SearchIntent(),
};
final _globalActions = <Type, Action<Intent>>{
CloseIntent: CallbackAction(onInvoke: (_) {
windowManager.close();
return null;
}),
SearchIntent: CallbackAction(onInvoke: (intent) {
// If the OATH view doesn't have focus, but is shown, find and select the search bar.
final searchContext = searchAccountsField.currentContext;
if (searchContext != null) {
if (!Navigator.of(searchContext).canPop()) {
return Actions.maybeInvoke(searchContext, intent);
}
}
return null;
}),
};
Widget registerGlobalShortcuts(Widget child) => Actions(
actions: _globalActions,
child: Shortcuts(
shortcuts: _globalShortcuts,
child: child,
),
);

View File

@ -24,7 +24,9 @@ const resetAction = Key('$_prefix.reset');
const noAccountsView = Key('$_prefix.no_accounts');
const searchAccountsField = Key('$_prefix.search_accounts');
// This is global so we can access it from the global Ctrl+F shortcut.
final searchAccountsField = GlobalKey();
const passwordField = Key('$_prefix.password');
const currentPasswordField = Key('$_prefix.current_password');
const newPasswordField = Key('$_prefix.new_password');