Skip to content

Commit

Permalink
Implement exiting search on escape presses (#310, #299)
Browse files Browse the repository at this point in the history
  • Loading branch information
merlettoth committed Jan 10, 2023
1 parent f7cf8dc commit 87f58cc
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ All user visible changes to this project will be documented in this file. This p
- Chats tab:
- Chat muting/unmuting. ([#251], [#172], [#63])
- Favorite chats. ([#218], [#209])
- Searching. ([#206], [#205])
- Searching. ([#310], [#206], [#205])
- Home page:
- Quick status changing menu. ([#275], [#204], [#203])
- Media panel:
- Participants redialing. ([#241], [#233])
- Screen share display choosing on desktop. ([#228], [#222])
- Contacts tab:
- Favorite contacts. ([#285], [#237], [#223])
- Searching. ([#260], [#259])
- Searching. ([#310], [#260], [#259])
- User page:
- Blacklisting. ([#277], [#234], [#229])
- Window's size and position persistence. ([#274], [#263])
Expand Down Expand Up @@ -137,6 +137,7 @@ All user visible changes to this project will be documented in this file. This p
[#292]: /../../issues/292
[#293]: /../../pull/293
[#300]: /../../pull/300
[#310]: /../../pull/310



Expand Down
23 changes: 23 additions & 0 deletions lib/ui/page/home/tab/chats/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import 'dart:collection';

import 'package:async/async.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';

import '/domain/model/chat.dart';
Expand Down Expand Up @@ -138,6 +139,9 @@ class ChatsTabController extends GetxController {
@override
void onInit() {
chats = RxList<RxChat>(_chatService.chats.values.toList());

HardwareKeyboard.instance.addHandler(_escapeListener);

_sortChats();

for (RxChat chat in chats) {
Expand Down Expand Up @@ -209,6 +213,8 @@ class ChatsTabController extends GetxController {

@override
void onClose() {
HardwareKeyboard.instance.removeHandler(_escapeListener);

for (var data in _sortingData.values) {
data.dispose();
}
Expand Down Expand Up @@ -532,6 +538,23 @@ class ChatsTabController extends GetxController {
closeSearch(!groupCreating.value);
}
}

/// Closes the [searching] on the [LogicalKeyboardKey.escape] events.
///
/// Intended to be used as a [HardwareKeyboard] listener.
bool _escapeListener(KeyEvent e) {
if (e is KeyDownEvent && e.logicalKey == LogicalKeyboardKey.escape) {
if (searching.value) {
closeSearch(!groupCreating.value);
return true;
} else if (groupCreating.value) {
closeGroupCreating();
return true;
}
}

return false;
}
}

/// Container of data used to sort a [Chat].
Expand Down
20 changes: 20 additions & 0 deletions lib/ui/page/home/tab/contacts/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import 'dart:async';

import 'package:async/async.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';

import '/domain/model/chat.dart';
Expand Down Expand Up @@ -121,6 +122,8 @@ class ContactsTabController extends GetxController {

_initUsersUpdates();

HardwareKeyboard.instance.addHandler(_escapeListener);

super.onInit();
}

Expand All @@ -134,6 +137,9 @@ class ContactsTabController extends GetxController {
_favoritesSubscription?.cancel();
_rxUserWorkers.forEach((_, v) => v.dispose());
_userWorkers.forEach((_, v) => v.dispose());

HardwareKeyboard.instance.removeHandler(_escapeListener);

super.onClose();
}

Expand Down Expand Up @@ -406,4 +412,18 @@ class ContactsTabController extends GetxController {
toggleSearch(false);
}
}

/// Closes the [search]ing on the [LogicalKeyboardKey.escape] events.
///
/// Intended to be used as a [HardwareKeyboard] listener.
bool _escapeListener(KeyEvent e) {
if (e is KeyDownEvent && e.logicalKey == LogicalKeyboardKey.escape) {
if (search.value != null) {
toggleSearch(false);
return true;
}
}

return false;
}
}

0 comments on commit 87f58cc

Please sign in to comment.