From 40c7ef49c566e0e4882dc11790d5ff3b3a5368e4 Mon Sep 17 00:00:00 2001 From: Gabby Gurdin Date: Wed, 21 Feb 2024 14:35:23 -0500 Subject: [PATCH] update toolbar after highlight change --- lib/pangea/widgets/chat/message_toolbar.dart | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/pangea/widgets/chat/message_toolbar.dart b/lib/pangea/widgets/chat/message_toolbar.dart index 5b91181c1..aa8a1de7b 100644 --- a/lib/pangea/widgets/chat/message_toolbar.dart +++ b/lib/pangea/widgets/chat/message_toolbar.dart @@ -247,14 +247,16 @@ class MessageToolbarState extends State { updateMode(mode); }); + Timer? timer; + selectionStream = widget.textSelection.selectionStream.stream.listen((value) { - final bool shouldSetState = - value != null && !hasSelectedText || value == null && hasSelectedText; - hasSelectedText = value != null; - if (shouldSetState) { - setState(() {}); - } + timer?.cancel(); + timer = Timer(const Duration(milliseconds: 750), () { + if (currentMode != null || value != null && value.isNotEmpty) { + updateMode(currentMode ?? MessageMode.translation); + } + }); }); }