Skip to content

Commit 9983687

Browse files
committed
fix(mobile): state inline code without restyling the rest of Markdown
Registering a `GptMarkdownThemeData` as a `ThemeExtension` is not a partial override. Its factory builds a fresh stock Material theme and fills every heading, rule and highlight field from that, so registering one stops `GptMarkdownTheme.of` deriving those from the app. Measured against the previous head, on light and dark alike: H1 fell from w600 to w400 and lost Inter altogether, H4 from 24 to 22sp, H5 from 20 to 16sp, and horizontal rules went from the app's `outline` to Material gray — on messages holding no code at all. Restating those fields in the extension does not close the gap: the ambient headings carry the localized text geometry, which exists only once `Theme.of` has run, and a `ThemeData` factory cannot see it, so `inherit`, `leadingDistribution` and `baseline` still differ. Overriding the one field on the ambient theme is what leaves non-code Markdown untouched, so the code style now comes from an `AppMarkdownTheme` above the navigator. The same package upgrade turned autolinking on by default in the two agent transcript renderers, neither of which passes a link handler: a bare URL drew as a link and then did nothing when tapped. Both opt out, keeping the 1.1.6 behaviour. Giving transcript URLs a working handler is a separate change. Tests: the Markdown theme a widget reads with the app's code style stated is compared field by field against the ambient one, and both transcript surfaces are asserted to render a bare URL without a `LinkButton`. Reverting either fix fails them. Signed-off-by: Tolga Cinisli <[email protected]>
1 parent db0c922 commit 9983687

8 files changed

Lines changed: 189 additions & 26 deletions

File tree

‎mobile/lib/app.dart‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,11 @@ class App extends HookConsumerWidget {
130130
// Above the navigator, so a burst keeps playing over a pushed thread page
131131
// or a modal sheet — the same reason desktop pins its canvas to the
132132
// viewport rather than to the message row.
133-
builder: (context, child) => MobileHuddleShell(
134-
navigatorKey: _mobileRootNavigatorKey,
135-
child: EmojiBurstOverlay(child: child ?? const SizedBox.shrink()),
133+
builder: (context, child) => AppMarkdownTheme(
134+
child: MobileHuddleShell(
135+
navigatorKey: _mobileRootNavigatorKey,
136+
child: EmojiBurstOverlay(child: child ?? const SizedBox.shrink()),
137+
),
136138
),
137139
home: authState.when(
138140
loading: () => const _SplashScreen(),

‎mobile/lib/features/channels/agent_activity/transcript_item_widget.dart‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ class _MessageItemWidget extends StatelessWidget {
7272
style: context.textTheme.bodyMedium?.copyWith(
7373
color: context.colors.onSurface,
7474
),
75+
// No link handler here, so an autolinked URL would draw as a
76+
// link and do nothing when tapped. Transcript URLs stay text,
77+
// as they were before gpt_markdown started autolinking.
78+
autolink: false,
7579
),
7680
],
7781
),
@@ -143,6 +147,8 @@ class _ThoughtItemWidget extends HookWidget {
143147
style: context.textTheme.bodySmall?.copyWith(
144148
color: context.colors.onSurfaceVariant,
145149
),
150+
// As above: no link handler on this surface either.
151+
autolink: false,
146152
),
147153
],
148154
],
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:gpt_markdown/gpt_markdown.dart';
3+
4+
import 'app_theme.dart';
5+
import 'code_style.dart';
6+
7+
/// States the app's code style on every `GptMarkdown` below it and leaves the
8+
/// rest of the Markdown theme as it already was.
9+
///
10+
/// Registering a [GptMarkdownThemeData] as a `ThemeExtension` would be the
11+
/// shorter route, but its factory is not a partial override: it builds a fresh
12+
/// stock Material theme and fills every heading, rule and highlight field from
13+
/// it, so registering one stops `GptMarkdownTheme.of` deriving those from the
14+
/// app. Restating them in the extension does not close the gap either — the
15+
/// ambient headings carry the localized text geometry, which exists only once
16+
/// `Theme.of` has run and a `ThemeData` factory cannot see. Overriding the one
17+
/// field on the ambient theme is what leaves non-code Markdown untouched.
18+
class AppMarkdownTheme extends StatelessWidget {
19+
const AppMarkdownTheme({super.key, required this.child});
20+
21+
final Widget child;
22+
23+
@override
24+
Widget build(BuildContext context) {
25+
final scheme = Theme.of(context).colorScheme;
26+
return GptMarkdownTheme(
27+
gptThemeData: GptMarkdownTheme.of(context).copyWith(
28+
// Inline code is otherwise drawn in gpt_markdown's own bundled face, at
29+
// its own size, tinted from `onSurface`. Stating the app's code style
30+
// gives every Markdown surface the face, size and chip colours a fenced
31+
// code block already uses.
32+
inlineCode: InlineCodeStyle(
33+
fontFamily: CodeStyle.fontFamily,
34+
fontSizeFactor: CodeStyle.fontSizeFactor,
35+
color: scheme.onSurface,
36+
backgroundColor: CodeStyle.background(scheme),
37+
borderColor: CodeStyle.border(scheme),
38+
// A chip is small, so it takes the smallest step of the app's radius
39+
// scale rather than the `Radii.card` a block uses.
40+
borderRadius: const Radius.circular(Radii.xs),
41+
).resolve(scheme),
42+
),
43+
child: child,
44+
);
45+
}
46+
}

‎mobile/lib/shared/theme/app_theme.dart‎

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ import 'package:flutter/material.dart';
22
import 'package:flutter/services.dart';
33

44
import 'app_colors.dart';
5-
import 'code_style.dart';
65
import 'color_scheme.dart';
76
import 'grid.dart';
87
import 'text_theme.dart';
9-
import 'package:gpt_markdown/gpt_markdown.dart';
108

119
/// Border radius constants matching desktop shadcn "New York" style.
1210
/// Desktop uses --radius: 0.625rem (10px) as base:
@@ -91,26 +89,7 @@ class AppTheme {
9189
colorScheme: scheme,
9290
splashFactory: NoSplash.splashFactory,
9391
scaffoldBackgroundColor: scheme.surface,
94-
extensions: [
95-
appColors,
96-
// Inline code is rendered by gpt_markdown, which otherwise draws it in
97-
// its own bundled face, at its own size, tinted from `onSurface`.
98-
// Stating the app's code style here gives every Markdown surface the
99-
// face, size and chip colours a fenced code block already uses.
100-
GptMarkdownThemeData(
101-
brightness: brightness,
102-
inlineCode: InlineCodeStyle(
103-
fontFamily: CodeStyle.fontFamily,
104-
fontSizeFactor: CodeStyle.fontSizeFactor,
105-
color: scheme.onSurface,
106-
backgroundColor: CodeStyle.background(scheme),
107-
borderColor: CodeStyle.border(scheme),
108-
// A chip is small, so it takes the smallest step of the app's
109-
// radius scale rather than the `Radii.card` a block uses.
110-
borderRadius: const Radius.circular(Radii.xs),
111-
),
112-
),
113-
],
92+
extensions: [appColors],
11493
fontFamily: 'Inter',
11594
textTheme: textTheme,
11695
appBarTheme: AppBarTheme(

‎mobile/lib/shared/theme/theme.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export 'accent_colors.dart';
22
export 'adaptive_theme.dart';
33
export 'app_colors.dart';
4+
export 'app_markdown_theme.dart';
45
export 'app_theme.dart';
56
export 'buzz_theme.dart';
67
export 'code_style.dart';
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:gpt_markdown/custom_widgets/link_button.dart';
4+
import 'package:buzz/features/channels/agent_activity/observer_models.dart';
5+
import 'package:buzz/features/channels/agent_activity/transcript_item_widget.dart';
6+
import 'package:buzz/shared/theme/theme.dart';
7+
8+
Widget _testable(Widget child) {
9+
return MaterialApp(
10+
theme: AppTheme.light(),
11+
home: Scaffold(body: SingleChildScrollView(child: child)),
12+
);
13+
}
14+
15+
void main() {
16+
// Neither transcript surface passes a link handler, so an autolinked bare
17+
// URL would draw as a link and then do nothing when tapped. They stay text.
18+
testWidgets('leaves a bare URL in a message as plain text', (tester) async {
19+
await tester.pumpWidget(
20+
_testable(
21+
TranscriptItemWidget(
22+
item: MessageItem(
23+
id: 'm1',
24+
role: 'assistant',
25+
title: 'Assistant',
26+
text: 'Report is at https://example.com/report today.',
27+
timestamp: '2026-08-29T09:00:00Z',
28+
),
29+
),
30+
),
31+
);
32+
33+
expect(find.byType(LinkButton), findsNothing);
34+
});
35+
36+
testWidgets('leaves a bare URL in a thought as plain text', (tester) async {
37+
await tester.pumpWidget(
38+
_testable(
39+
TranscriptItemWidget(
40+
item: ThoughtItem(
41+
id: 't1',
42+
title: 'Thinking',
43+
text: 'Checking https://example.com/report first.',
44+
timestamp: '2026-08-29T09:00:00Z',
45+
),
46+
),
47+
),
48+
);
49+
50+
expect(find.byType(LinkButton), findsNothing);
51+
});
52+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ Widget _testable(
3535
data: MediaQuery.of(
3636
context,
3737
).copyWith(disableAnimations: disableAnimations),
38-
child: Scaffold(body: child),
38+
// The app states its code style here, above the navigator.
39+
child: AppMarkdownTheme(child: Scaffold(body: child)),
3940
),
4041
),
4142
),
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:gpt_markdown/gpt_markdown.dart';
4+
import 'package:buzz/shared/theme/app_markdown_theme.dart';
5+
import 'package:buzz/shared/theme/app_theme.dart';
6+
import 'package:buzz/shared/theme/code_style.dart';
7+
8+
/// The Markdown theme a widget reads under [theme], with [wrapped] deciding
9+
/// whether the app states its code style above it.
10+
Future<GptMarkdownThemeData> _markdownTheme(
11+
WidgetTester tester,
12+
ThemeData theme, {
13+
required bool wrapped,
14+
}) async {
15+
late GptMarkdownThemeData read;
16+
final reader = Builder(
17+
builder: (context) {
18+
read = GptMarkdownTheme.of(context);
19+
return const SizedBox.shrink();
20+
},
21+
);
22+
23+
await tester.pumpWidget(
24+
MaterialApp(
25+
theme: theme,
26+
home: wrapped ? AppMarkdownTheme(child: reader) : reader,
27+
),
28+
);
29+
// MaterialApp animates a theme change, so the first frame after a pump can
30+
// still carry the previous one.
31+
await tester.pumpAndSettle();
32+
return read;
33+
}
34+
35+
void main() {
36+
testWidgets('states inline code and leaves the rest of Markdown alone', (
37+
tester,
38+
) async {
39+
for (final theme in [AppTheme.light(), AppTheme.dark()]) {
40+
final ambient = await _markdownTheme(tester, theme, wrapped: false);
41+
final stated = await _markdownTheme(tester, theme, wrapped: true);
42+
43+
// Headings, rules and the rest keep the values gpt_markdown derives from
44+
// the app theme: a code-only change must not restyle anything else.
45+
expect(stated.h1, ambient.h1);
46+
expect(stated.h2, ambient.h2);
47+
expect(stated.h3, ambient.h3);
48+
expect(stated.h4, ambient.h4);
49+
expect(stated.h5, ambient.h5);
50+
expect(stated.h6, ambient.h6);
51+
expect(stated.hrLineColor, ambient.hrLineColor);
52+
expect(stated.hrLineThickness, ambient.hrLineThickness);
53+
expect(stated.hrLinePadding, ambient.hrLinePadding);
54+
expect(stated.highlightColor, ambient.highlightColor);
55+
expect(stated.linkColor, ambient.linkColor);
56+
expect(stated.linkHoverColor, ambient.linkHoverColor);
57+
expect(
58+
stated.autoAddDividerLineAfterH1,
59+
ambient.autoAddDividerLineAfterH1,
60+
);
61+
expect(stated.styleSheet, ambient.styleSheet);
62+
63+
// Inline code is the whole of the difference.
64+
final scheme = theme.colorScheme;
65+
expect(stated.inlineCode.fontFamily, CodeStyle.fontFamily);
66+
expect(stated.inlineCode.color, scheme.onSurface);
67+
expect(stated.inlineCode.backgroundColor, CodeStyle.background(scheme));
68+
expect(stated.inlineCode.borderColor, CodeStyle.border(scheme));
69+
expect(
70+
ambient.inlineCode.fontFamily,
71+
isNot(CodeStyle.fontFamily),
72+
reason: 'the package default is what this widget exists to replace',
73+
);
74+
}
75+
});
76+
}

0 commit comments

Comments
 (0)