Skip to content

Commit 82746fe

Browse files
loganjLarryclaude
committed
fix(mobile): keep authored edited-slot characters
The renderer removed every U+E0ED from message bodies, so an authored private-use character was lost, even in unedited messages. Now the marker component applies only to an edited body without that character. An edited body that has one keeps it and shows "(edited)" on its own line. Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Logan Johnson <[email protected]>
1 parent 4cde2c1 commit 82746fe

4 files changed

Lines changed: 22 additions & 11 deletions

File tree

‎mobile/lib/features/channels/message_content.dart‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ class MessageContent extends HookConsumerWidget {
361361
// so the gpt_markdown combined regex can match multi-word names
362362
// even when caseSensitive is not preserved.
363363
// Skip content inside backticks to avoid altering inline code.
364-
final mentionParts = withoutEditedSlot(markdownContent).split('`');
364+
final mentionParts = markdownContent.split('`');
365365
final mentionBuf = StringBuffer();
366366
for (var i = 0; i < mentionParts.length; i++) {
367367
if (i.isOdd) {
@@ -408,9 +408,11 @@ class MessageContent extends HookConsumerWidget {
408408
onChannelTap: resolvedChannelTap,
409409
);
410410
final editedStyle = editedMarkerStyle(context, own: bubble && ownMessage);
411+
// An authored slot is drawn as written; the marker takes its own line.
412+
final markerSlot = edited && !finalContent.contains(editedSlot);
411413
final components = useMemoized(
412-
() => [EditedMarkerMd(editedStyle), ...inlineComponents],
413-
[inlineComponents, editedStyle],
414+
() => [if (markerSlot) EditedMarkerMd(editedStyle), ...inlineComponents],
415+
[inlineComponents, editedStyle, markerSlot],
414416
);
415417

416418
Widget renderMarkdown(String text) => KeyedSubtree(

‎mobile/lib/features/channels/message_content/edited_marker.dart‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ import 'package:gpt_markdown/gpt_markdown.dart';
44
import '../../../shared/theme/theme.dart';
55

66
/// Marks where an edited body draws its "(edited)" marker. A private-use
7-
/// character, removed from authored content, so only the renderer adds it.
7+
/// character. A body that already has one is drawn as written, and its
8+
/// marker takes its own line.
89
const editedSlot = '';
910

10-
/// [text] without authored edited slots, so only the renderer places one.
11-
String withoutEditedSlot(String text) => text.replaceAll(editedSlot, '');
12-
1311
/// The visible text of the edited marker.
1412
const editedMarkerText = '(edited)';
1513

@@ -31,10 +29,13 @@ final _block = RegExp(
3129
/// marker must take its own line instead. It joins prose (a paragraph, list
3230
/// item or quote). Bodies with a code fence anywhere never get the
3331
/// slot: gpt_markdown's fence rules differ from CommonMark, so the slot could
34-
/// land inside code or open a new block.
32+
/// land inside code or open a new block. Bodies with an authored slot never
33+
/// get one either, so that character is not drawn as the marker.
3534
String? withEditedSlot(String markdown) {
3635
final body = markdown.trimRight();
37-
if (body.isEmpty || body.contains('```')) return null;
36+
if (body.isEmpty || body.contains('```') || body.contains(editedSlot)) {
37+
return null;
38+
}
3839
final last = body.substring(body.lastIndexOf('\n') + 1);
3940
if (_block.hasMatch(last) || _endsInLink(last)) return null;
4041
return '$body $editedSlot';

‎mobile/test/features/channels/message_content/edited_marker_test.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ void main() {
6161
'go to(https://x.io',
6262
'see x+1.y-z://host',
6363
'buzz://message?channel=c&id=e',
64+
'kept $editedSlot as written',
6465
]) {
6566
expect(withEditedSlot(markdown), isNull, reason: markdown);
6667
}

‎mobile/test/features/channels/message_content_bubble_cases.dart‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,11 +423,18 @@ void editedMarkerTests() {
423423
findsNothing,
424424
);
425425

426-
// Unedited bodies, including authored slot characters, stay unmarked.
426+
// Unedited bodies stay unmarked. An authored slot character is drawn as
427+
// written, and only an edit adds the marker, on its own line.
428+
bool shows(String text) => tester
429+
.widgetList<RichText>(find.byType(RichText))
430+
.any((rich) => rich.text.toPlainText().contains(text));
427431
await show('Plain', edited: false);
428432
expect(markerSpan(tester), isNull);
429433
await show('Sneaky $editedSlot', edited: false);
434+
expect(shows('Sneaky $editedSlot'), isTrue);
430435
expect(markerSpan(tester), isNull);
431-
expect(find.text('(edited)'), findsNothing);
436+
await show('Sneaky $editedSlot');
437+
expect(shows('Sneaky $editedSlot'), isTrue);
438+
expect(find.text('(edited)'), findsOneWidget);
432439
});
433440
}

0 commit comments

Comments
 (0)