Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

A tag the text does not say opens its first line (#2279)

0xken153e19a61013e1
diff --git a/desktop/lib/super_tabs/message_text.dart b/desktop/lib/super_tabs/message_text.dart
index e7117a937..d01b528bd 100644
--- a/desktop/lib/super_tabs/message_text.dart
+++ b/desktop/lib/super_tabs/message_text.dart
@@ -23,7 +23,7 @@ class SuperTabMessageText extends StatelessWidget {
final ValueChanged<String>? onOpenGroup;
/// The names a Lead tagged in this message. Each reads highlighted where
- /// the text says it; one the text does not say is shown before it.
+ /// the text says it; one the text does not say opens its first line.
final List<String> mentions;
static Uri? webLink(String? href) {
@@ -35,6 +35,24 @@ class SuperTabMessageText extends StatelessWidget {
: null;
}
+ /// [tags] on the first line of [text], as a person types them in chat.
+ /// Only text that opens with a block (a list, heading, quote, table, code,
+ /// divider or link definition) keeps them on a line of their own, so that
+ /// block still renders.
+ static String withTags(List<String> tags, String text) {
+ if (tags.isEmpty) return text;
+ final body = text.replaceFirst(RegExp(r'^(?:[ \t]*\n)+'), '');
+ return _opensBlock.hasMatch(body)
+ ? '${tags.join(' ')}\n\n$body'
+ : '${tags.join(' ')} $body';
+ }
+
+ static final _opensBlock = RegExp(
+ r'^(?: {4}|\t| {0,3}(?:[-*+](?:[ \t\n]|$)|#{1,6}(?:[ \t\n]|$)|>'
+ r'|\d{1,9}[.)](?:[ \t\n]|$)|```|~~~|\||\[[^\]\n]+\]:'
+ r'|(?:(?:\*[ \t]*){3,}|(?:-[ \t]*){3,}|(?:_[ \t]*){3,})(?:\n|$)))',
+ );
+
@override
Widget build(BuildContext context) {
grid.AppTheme.watch(context);
@@ -44,7 +62,7 @@ class SuperTabMessageText extends StatelessWidget {
'@$name',
];
return MarkdownBody(
- data: unsaid.isEmpty ? text : '${unsaid.join(' ')}\n\n$text',
+ data: withTags(unsaid, text),
selectable: false,
softLineBreak: true,
inlineSyntaxes: [
diff --git a/desktop/test/super_tab_mentions_test.dart b/desktop/test/super_tab_mentions_test.dart
index a79a21d1b..b2bb38435 100644
--- a/desktop/test/super_tab_mentions_test.dart
+++ b/desktop/test/super_tab_mentions_test.dart
@@ -916,15 +916,74 @@ void main() {
);
});
- testWidgets('a tag the text does not say is shown before it', (
+ testWidgets('a tag the text does not say opens its first line', (
tester,
) async {
await showText(tester, 'Please confirm the release.', ['dee']);
expect(runsOf(tester, '@dee').single?.backgroundColor, isNotNull);
+ // Same line as the text, as a person types it; never a line of its own.
expect(
- find.textContaining('Please confirm the release.'),
+ find.text('@dee Please confirm the release.', findRichText: true),
findsOneWidget,
);
+ expect(find.text('@dee', findRichText: true), findsNothing);
+ });
+
+ testWidgets('several unsaid tags open the first line of a longer text', (
+ tester,
+ ) async {
+ await showText(
+ tester,
+ '\nShipped this morning:\n- Desktop 1.3.41\n- web 1.3.82',
+ ['ken', 'dee'],
+ );
+ expect(
+ find.text('@ken @dee Shipped this morning:', findRichText: true),
+ findsOneWidget,
+ );
+ expect(find.text('Desktop 1.3.41', findRichText: true), findsOneWidget);
+ });
+
+ test('a tag joins the first line unless the text opens with a block', () {
+ String tagged(String text) =>
+ SuperTabMessageText.withTags(['@dee'], text);
+ expect(tagged('#2259 merged.'), '@dee #2259 merged.');
+ expect(tagged('-5 degrees'), '@dee -5 degrees');
+ expect(tagged('2026 plan'), '@dee 2026 plan');
+ expect(tagged('Hi'), '@dee Hi');
+ expect(tagged('***Important*** now'), '@dee ***Important*** now');
+ expect(tagged('__init__ runs'), '@dee __init__ runs');
+ expect(
+ tagged('[link](https://example.com) here'),
+ '@dee [link](https://example.com) here',
+ );
+ // A list, heading, quote, table or code keeps rendering as one.
+ for (final block in [
+ '- one\n- two',
+ '* one',
+ '1. one',
+ '# Title',
+ '> quoted',
+ '| a | b |\n|---|---|',
+ '```\ncode\n```',
+ ' indented code',
+ '---',
+ '***',
+ '- - -',
+ '-\nnext',
+ '1.\nnext',
+ '[1]: https://example.com',
+ ]) {
+ expect(tagged(block), '@dee\n\n$block', reason: block);
+ }
+ expect(SuperTabMessageText.withTags(const [], 'Hi'), 'Hi');
+ });
+
+ testWidgets('a text that opens with a list keeps its list', (tester) async {
+ await showText(tester, '- one\n- two', ['dee']);
+ expect(find.text('one', findRichText: true), findsOneWidget);
+ expect(find.text('@dee', findRichText: true), findsOneWidget);
+ expect(runsOf(tester, '@dee').single?.backgroundColor, isNotNull);
});
testWidgets('a tag in code stays code', (tester) async {