From 1b74049eb58b8f3904cae1a73fb321b9eff97349 Mon Sep 17 00:00:00 2001 From: Aman Raj Date: Tue, 31 Dec 2024 15:52:13 +0530 Subject: [PATCH] [auth] ctrl+f to activate search box for icons --- auth/lib/ui/custom_icon_page.dart | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/auth/lib/ui/custom_icon_page.dart b/auth/lib/ui/custom_icon_page.dart index fa02c85667..428871d7c0 100644 --- a/auth/lib/ui/custom_icon_page.dart +++ b/auth/lib/ui/custom_icon_page.dart @@ -4,6 +4,7 @@ import 'package:ente_auth/services/preference_service.dart'; import 'package:ente_auth/theme/ente_theme.dart'; import 'package:ente_auth/ui/utils/icon_utils.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; class CustomIconPage extends StatefulWidget { final Map allIcons; @@ -29,12 +30,14 @@ class _CustomIconPageState extends State { // Used to request focus on the search box when clicked the search icon late FocusNode searchBoxFocusNode; + final Set _pressedKeys = {}; @override void initState() { _filteredIcons = widget.allIcons; _showSearchBox = _autoFocusSearch; searchBoxFocusNode = FocusNode(); + ServicesBinding.instance.keyboard.addHandler(_handleKeyEvent); super.initState(); } @@ -42,9 +45,41 @@ class _CustomIconPageState extends State { void dispose() { _textController.dispose(); searchBoxFocusNode.dispose(); + ServicesBinding.instance.keyboard.removeHandler(_handleKeyEvent); super.dispose(); } + bool _handleKeyEvent(KeyEvent event) { + if (event is KeyDownEvent) { + setState(() { + _pressedKeys.add(event.logicalKey); + if ((_pressedKeys.contains(LogicalKeyboardKey.controlLeft) || + _pressedKeys.contains(LogicalKeyboardKey.control) || + _pressedKeys.contains(LogicalKeyboardKey.controlRight)) && + event.logicalKey == LogicalKeyboardKey.keyF) { + _showSearchBox = true; + searchBoxFocusNode.requestFocus(); + _textController.clear(); + _searchText = ""; + return; + } + if (event.logicalKey == LogicalKeyboardKey.escape) { + setState(() { + _textController.clear(); + _searchText = ""; + _showSearchBox = false; + _applyFilteringAndRefresh(); + }); + } else if (event is KeyUpEvent) { + setState(() { + _pressedKeys.remove(event.logicalKey); + }); + } + }); + } + return false; + } + void _applyFilteringAndRefresh() { if (_searchText.isEmpty) { setState(() {