From 0428119c8ab61847576f848abaf80294fb9d6e18 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Fri, 6 Nov 2020 10:31:39 +0100 Subject: [PATCH] fix performance and highlight text --- example/ios/Flutter/.last_build_id | 2 +- example/pubspec.yaml | 2 +- lib/src/message_input.dart | 38 +++++++++++++----------------- pubspec.yaml | 2 +- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/example/ios/Flutter/.last_build_id b/example/ios/Flutter/.last_build_id index 5d3809be..8aba7787 100644 --- a/example/ios/Flutter/.last_build_id +++ b/example/ios/Flutter/.last_build_id @@ -1 +1 @@ -bdf1751976c4ee1e2ef7638eabcfd1ea \ No newline at end of file +bb5f9103d9045cd6244bcae1f5f343e5 \ No newline at end of file diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 842f471c..97971445 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,6 +1,6 @@ name: example description: A new Flutter project. -version: 1.0.39+41 +version: 1.0.40+42 environment: sdk: ">=2.2.2 <3.0.0" diff --git a/lib/src/message_input.dart b/lib/src/message_input.dart index 1acdd64b..b2d124da 100644 --- a/lib/src/message_input.dart +++ b/lib/src/message_input.dart @@ -7,7 +7,6 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart'; -import 'package:fuzzy/fuzzy.dart'; import 'package:http_parser/http_parser.dart'; import 'package:image_picker/image_picker.dart'; import 'package:mime/mime.dart'; @@ -15,6 +14,7 @@ import 'package:stream_chat/stream_chat.dart'; import 'package:stream_chat_flutter/src/message_list_view.dart'; import 'package:stream_chat_flutter/src/stream_chat_theme.dart'; import 'package:stream_chat_flutter/src/user_avatar.dart'; +import 'package:substring_highlight/substring_highlight.dart'; import '../stream_chat_flutter.dart'; import 'stream_channel.dart'; @@ -170,7 +170,7 @@ class MessageInputState extends State { bool _typingStarted = false; bool _commandEnabled = false; OverlayEntry _commandsOverlay, _mentionsOverlay, _emojiOverlay; - Fuzzy _emojiFuse; + Iterable _emojiNames; Command _chosenCommand; bool _actionsShrunk = false; @@ -403,8 +403,6 @@ class MessageInputState extends State { 0, textEditingController.selection.start, ) - .split(' ') - .last .contains(':'))) { final textToSelection = textEditingController.text .substring(0, textEditingController.value.selection.start); @@ -676,11 +674,8 @@ class MessageInputState extends State { return null; } - final emojis = _emojiFuse - .search(query) - .map((e) => Emoji.byName(e.item)) - .where((e) => e != null) - .toList(); + final emojis = + _emojiNames.where((e) => e.contains(query)).map((e) => Emoji.byName(e)); if (emojis.isEmpty) { return null; @@ -743,14 +738,19 @@ class MessageInputState extends State { ); } - final emoji = emojis[i - 1]; + final emoji = emojis.elementAt(i - 1); return ListTile( - title: Text( - "${emoji.char} ${emoji.name.replaceAll('_', ' ')}", - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 14.5, - ), + title: SubstringHighlight( + text: "${emoji.char} ${emoji.name.replaceAll('_', ' ')}", + term: query, + textStyleHighlight: + Theme.of(context).textTheme.headline6.copyWith( + fontSize: 14.5, + fontWeight: FontWeight.bold, + ), + textStyle: Theme.of(context).textTheme.headline6.copyWith( + fontSize: 14.5, + ), ), onTap: () { _chooseEmoji(splits, emoji); @@ -1334,11 +1334,7 @@ class MessageInputState extends State { void initState() { super.initState(); - _emojiFuse = Fuzzy(Emoji.all().map((e) => e.name).toList(), - options: FuzzyOptions( - matchAllTokens: true, - tokenize: true, - )); + _emojiNames = Emoji.all().map((e) => e.name); if (!kIsWeb) { _keyboardListener = KeyboardVisibility.onChange.listen((visible) { diff --git a/pubspec.yaml b/pubspec.yaml index 6aa8aff3..eb9f0545 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -27,9 +27,9 @@ dependencies: stream_chat: ^0.2.10+1 emojis: ^0.9.3 mime: ^0.9.6+3 - fuzzy: ^0.2.3 visibility_detector: ^0.1.5 http_parser: ^3.1.4 + substring_highlight: ^0.1.2 flutter_slidable: ^0.5.4 carousel_slider: ^2.2.1 clipboard: ^0.1.2+8