diff --git a/lib/widgets/content.dart b/lib/widgets/content.dart index b569f43b55..bc43f0b84b 100644 --- a/lib/widgets/content.dart +++ b/lib/widgets/content.dart @@ -454,7 +454,7 @@ class InlineContent extends StatelessWidget { @override Widget build(BuildContext context) { - return Text.rich(_builder.build()); + return Text.rich(_builder.build(context)); } } @@ -463,15 +463,21 @@ class _InlineContentBuilder { final InlineContent widget; - InlineSpan build() { + InlineSpan build(BuildContext context) { + assert(_context == null); + _context = context; assert(_recognizer == widget.recognizer); assert(_recognizerStack == null || _recognizerStack!.isEmpty); final result = _buildNodes(widget.nodes, style: widget.style); + assert(identical(_context, context)); + _context = null; assert(_recognizer == widget.recognizer); assert(_recognizerStack == null || _recognizerStack!.isEmpty); return result; } + BuildContext? _context; + // Why do we have to track `recognizer` here, rather than apply it // once at the top of the affected span? Because the events don't bubble // within a paragraph: @@ -531,7 +537,7 @@ class _InlineContentBuilder { } InlineSpan _buildStrong(StrongNode node) => _buildNodes(node.nodes, - style: const TextStyle(fontWeight: FontWeight.w600)); + style: weightVariableTextStyle(_context, wght: 600, wghtIfPlatformRequestsBold: 900)); InlineSpan _buildEmphasis(EmphasisNode node) => _buildNodes(node.nodes, style: const TextStyle(fontStyle: FontStyle.italic)); @@ -594,9 +600,18 @@ class _InlineContentBuilder { final _kInlineMathStyle = _kInlineCodeStyle.merge(TextStyle( backgroundColor: const HSLColor.fromAHSL(1, 240, 0.4, 0.93).toColor())); +// Even though [kMonospaceTextStyle] is a variable-weight font, +// it's acceptable to skip [weightVariableTextStyle] here, +// assuming the text gets the effect of [weightVariableTextStyle] +// through inheritance, e.g., from a [DefaultTextStyle]. final _kInlineCodeStyle = kMonospaceTextStyle .merge(const TextStyle( backgroundColor: Color(0xffeeeeee), + fontSize: 0.825 * kBaseFontSize)); + +final _kCodeBlockStyle = kMonospaceTextStyle + .merge(const TextStyle( + backgroundColor: Color.fromRGBO(255, 255, 255, 1), fontSize: 0.825 * kBaseFontSize)) .merge( // TODO(a11y) pass a BuildContext, to handle platform request for bold text. @@ -606,14 +621,6 @@ final _kInlineCodeStyle = kMonospaceTextStyle // frequently. Then consumers can just look it up on the InheritedWidget. weightVariableTextStyle(null)); -final _kCodeBlockStyle = kMonospaceTextStyle - .merge(const TextStyle( - backgroundColor: Color.fromRGBO(255, 255, 255, 1), - fontSize: 0.825 * kBaseFontSize)) - .merge( - // TODO(a11y) pass a BuildContext; see comment in _kInlineCodeStyle above. - weightVariableTextStyle(null)); - // const _kInlineCodeLeftBracket = '⸤'; // const _kInlineCodeRightBracket = '⸣'; // Some alternatives: diff --git a/lib/widgets/text.dart b/lib/widgets/text.dart index 4fb9e1cec7..5cc659abd1 100644 --- a/lib/widgets/text.dart +++ b/lib/widgets/text.dart @@ -200,8 +200,9 @@ TextStyle weightVariableTextStyle(BuildContext? context, { fontVariations: [FontVariation('wght', value)], // This use of `fontWeight` shouldn't affect glyphs in the preferred, - // "wght"-axis font. If it does, see for debugging: - // https://github.com/zulip/zulip-flutter/issues/65#issuecomment-1550666764 + // "wght"-axis font. But it can; see upstream bug: + // https://github.com/flutter/flutter/issues/136779 + // TODO(#500) await/send upstream bugfix? fontWeight: clampVariableFontWeight(value), inherit: true);