diff --git a/lib/pangea/widgets/chat/message_text_selection.dart b/lib/pangea/widgets/chat/message_text_selection.dart index 16982d9792..b41d62cbe3 100644 --- a/lib/pangea/widgets/chat/message_text_selection.dart +++ b/lib/pangea/widgets/chat/message_text_selection.dart @@ -1,12 +1,13 @@ import 'dart:async'; import 'package:flutter/foundation.dart'; -import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; class MessageTextSelection { String? selectedText; String messageText = ""; + final StreamController selectionStream = + StreamController.broadcast(); void setMessageText(String text) { messageText = text; @@ -21,7 +22,7 @@ class MessageTextSelection { if (BrowserContextMenu.enabled && kIsWeb) { BrowserContextMenu.disableContextMenu(); } - // selectionStream.add(selectedText); + selectionStream.add(selectedText); } void clearTextSelection() { @@ -29,6 +30,6 @@ class MessageTextSelection { if (kIsWeb && !BrowserContextMenu.enabled) { BrowserContextMenu.enableContextMenu(); } - // selectionStream.add(selectedText); + selectionStream.add(selectedText); } } diff --git a/lib/pangea/widgets/chat/message_toolbar.dart b/lib/pangea/widgets/chat/message_toolbar.dart index 2c74098660..18072d4688 100644 --- a/lib/pangea/widgets/chat/message_toolbar.dart +++ b/lib/pangea/widgets/chat/message_toolbar.dart @@ -141,6 +141,7 @@ class MessageToolbar extends StatefulWidget { class MessageToolbarState extends State { Widget? child; MessageMode? _currentMode; + bool hasSelectedText = false; late StreamSubscription _selectionStream; late StreamSubscription _toolbarModeStream; @@ -233,9 +234,23 @@ class MessageToolbarState extends State { @override void initState() { super.initState(); + if (widget.textSelection.selectedText != null) { + hasSelectedText = true; + } + _toolbarModeStream = widget.toolbarModeStream.stream.listen((mode) { updateMode(mode); }); + + _selectionStream = + widget.textSelection.selectionStream.stream.listen((value) { + final bool shouldSetState = + value != null && !hasSelectedText || value == null && hasSelectedText; + hasSelectedText = value != null; + if (shouldSetState) { + setState(() {}); + } + }); } @override