We're building compact message items by writing an invisible prefix
(stacked with an actual username), then the actual message, then
an invisible suffix (stack with an actual timestamp).
Currenty selecting a compact message text results in selecting the
invisible prefixes and suffixes as well, which results in unexpected
data being selected.
This patch makes these invisible hacky spacings unselectable so that
only the actual message can be selected and copied in the list.
---
Using SelectionArea gives better behavior when selecting the edges
of the line.
lib/page/buffer.dart | 32 ++++++++++++++++++++++----------
1 file changed, 22 insertions(+), 10 deletions(-)
diff --git a/lib/page/buffer.dart b/lib/page/buffer.dart
index 56cc234..323b960 100644
--- a/lib/page/buffer.dart+++ b/lib/page/buffer.dart
@@ -635,7 +635,7 @@ class _CompactMessageItem extends StatelessWidget {
}).toList();
List<Widget> stack = [];
- List<TextSpan> content = [];+ List<InlineSpan> content = []; if (!prevMsgSameSender) {
var colorSwatch = Colors.primaries[sender.hashCode % Colors.primaries.length];
@@ -646,9 +646,14 @@ class _CompactMessageItem extends StatelessWidget {
left: 0,
child: Text(sender, style: senderStyle),
));
- content.add(TextSpan(- text: sender,- style: senderStyle.apply(color: Color(0x00000000)),+ content.add(WidgetSpan(+ child: SelectionContainer.disabled(+ child: Text(+ sender,+ style: senderStyle.apply(color: Color(0x00000000)),+ semanticsLabel: '', // Make screen reader quiet+ ),+ ), ));
}
@@ -665,17 +670,24 @@ class _CompactMessageItem extends StatelessWidget {
right: 0,
child: Text(timeText, style: timeStyle),
));
- content.add(TextSpan(- text: timeText,- style: timeStyle.apply(color: Color(0x00000000)),+ content.add(WidgetSpan(+ child: SelectionContainer.disabled(+ child: Text(+ timeText,+ style: timeStyle.apply(color: Color(0x00000000)),+ semanticsLabel: '', // Make screen reader quiet+ ),+ ), ));
}
stack.add(Container(
margin: EdgeInsets.only(left: 4),
- child: SelectableText.rich(- TextSpan(- children: content,+ child: SelectionArea(+ child: Text.rich(+ TextSpan(+ children: content,+ ), ),
),
));
base-commit: 38c1594530bf34129b3b20353ac614973a5b9d26
--
2.44.0