From ebe7efe8dc51cd63dae3f6f4c9aac75f385319d3 Mon Sep 17 00:00:00 2001 From: TPF <61667947+T-P-F@users.noreply.github.com> Date: Tue, 11 Jun 2024 15:41:38 +0200 Subject: [PATCH] add selectable option to markdown --- lib/src/models/message_options.dart | 8 ++++++++ lib/src/widgets/message_row/default_message_text.dart | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/src/models/message_options.dart b/lib/src/models/message_options.dart index 15b0be9..edf4a15 100644 --- a/lib/src/models/message_options.dart +++ b/lib/src/models/message_options.dart @@ -39,6 +39,8 @@ class MessageOptions { this.timeFontSize = 10.0, this.timePadding = const EdgeInsets.only(top: 5), this.markdownStyleSheet, + this.markdownSelectable = true, + this.onMarkdownSelectionChanged, Color? timeTextColor, }) : _currentUserContainerColor = currentUserContainerColor, _currentUserTextColor = currentUserTextColor, @@ -230,4 +232,10 @@ class MessageOptions { /// Stylesheet for markdown message rendering final MarkdownStyleSheet? markdownStyleSheet; + + /// Make markdown selectable + final bool markdownSelectable; + + // Function to call when the user selects a markdown text + final void Function(String?, TextSelection, SelectionChangedCause?)? onMarkdownSelectionChanged; } diff --git a/lib/src/widgets/message_row/default_message_text.dart b/lib/src/widgets/message_row/default_message_text.dart index f3cd98a..b907e8c 100644 --- a/lib/src/widgets/message_row/default_message_text.dart +++ b/lib/src/widgets/message_row/default_message_text.dart @@ -94,7 +94,8 @@ class DefaultMessageText extends StatelessWidget { return isMarkdown ? MarkdownBody( data: text, - selectable: true, + selectable: messageOptions.markdownSelectable, + onSelectionChanged: messageOptions.onMarkdownSelectionChanged, styleSheet: messageOptions.markdownStyleSheet, onTapLink: (String value, String? href, String title) { if (href != null) {