-
Notifications
You must be signed in to change notification settings - Fork 323
content: Include inline styles (italic etc.) in what we pass to WidgetSpans #1821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
9f0757d
48d4cd5
61a118b
8310d37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -822,7 +822,7 @@ class MathBlock extends StatelessWidget { | |
child: SingleChildScrollViewWithScrollbar( | ||
scrollDirection: Axis.horizontal, | ||
child: KatexWidget( | ||
textStyle: ContentTheme.of(context).textStylePlainParagraph, | ||
ambientTextStyle: ContentTheme.of(context).textStylePlainParagraph, | ||
nodes: nodes)))); | ||
} | ||
} | ||
|
@@ -1081,10 +1081,21 @@ class _InlineContentBuilder { | |
_recognizer = _recognizerStack!.removeLast(); | ||
} | ||
|
||
InlineSpan _buildNodes(List<InlineContentNode> nodes, {required TextStyle? style}) { | ||
final List<TextStyle> _styleStack = []; | ||
|
||
TextStyle _resolveStyleStack() { | ||
assert(_styleStack.isNotEmpty); // first item is `widget.style` | ||
return _styleStack.reduce((value, element) => value.merge(element)); | ||
} | ||
|
||
InlineSpan _buildNodes(List<InlineContentNode> nodes, {required TextStyle style}) { | ||
_styleStack.add(style); | ||
final children = nodes.map(_buildNode).toList(growable: false); | ||
_styleStack.removeLast(); | ||
|
||
return TextSpan( | ||
style: style, | ||
children: nodes.map(_buildNode).toList(growable: false)); | ||
children: children); | ||
} | ||
|
||
InlineSpan _buildNode(InlineContentNode node) { | ||
|
@@ -1123,7 +1134,7 @@ class _InlineContentBuilder { | |
|
||
case UserMentionNode(): | ||
return WidgetSpan(alignment: PlaceholderAlignment.middle, | ||
child: UserMention(ambientTextStyle: widget.style, node: node)); | ||
child: UserMention(ambientTextStyle: _resolveStyleStack(), node: node)); | ||
Comment on lines
-1126
to
+1137
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The contrast between _resolveStyleStack here, and I puzzled over it for a few minutes, basically until I remembered your recent other PR #1820. IIUC, the point is that for a TextSpan, its styles will get automatically merged with those of its ancestors; but a WidgetSpan makes a barrier to that automatic merging. So that'd be good to clarify. As doc on _resolveStyleStack if nothing else; and maybe add a getter for |
||
|
||
case UnicodeEmojiNode(): | ||
return TextSpan(text: node.emojiUnicode, recognizer: _recognizer, | ||
|
@@ -1145,11 +1156,11 @@ class _InlineContentBuilder { | |
: WidgetSpan( | ||
alignment: PlaceholderAlignment.baseline, | ||
baseline: TextBaseline.alphabetic, | ||
child: KatexWidget(textStyle: widget.style, nodes: nodes)); | ||
child: KatexWidget(ambientTextStyle: _resolveStyleStack(), nodes: nodes)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes me a little nervous performance-wise. What if there's a paragraph with 40 different inline math spans in it? (Imagine they're all short, like "x", "a^2", "y = 1", "\sin x".) I guess it only matters if the whole thing is inside a styled span. But that's not uncommon in math texts: the whole statement of a theorem is commonly set in italics. Maybe the first thing to do is to just measure, in a profile build, how long it takes to build a paragraph like that. If it's negligible, then great. If that's more than negligible, then a good solution could be to have |
||
|
||
case GlobalTimeNode(): | ||
return WidgetSpan(alignment: PlaceholderAlignment.middle, | ||
child: GlobalTime(node: node, ambientTextStyle: widget.style)); | ||
child: GlobalTime(node: node, ambientTextStyle: _resolveStyleStack())); | ||
|
||
case UnimplementedInlineContentNode(): | ||
return _errorUnimplemented(node, context: _context!); | ||
|
@@ -1341,7 +1352,7 @@ class GlobalTime extends StatelessWidget { | |
size: ambientTextStyle.fontSize!, | ||
// (When GlobalTime appears in a link, it should be blue | ||
// like the text.) | ||
color: DefaultTextStyle.of(context).style.color!, | ||
color: ambientTextStyle.color, | ||
ZulipIcons.clock), | ||
// Ad-hoc spacing adjustment per feedback: | ||
// https://chat.zulip.org/#narrow/stream/101-design/topic/clock.20icons/near/1729345 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other potential performance worry here is that we're now allocating these lists for every paragraph, even trivial short paragraphs with no formatting in them.
So that'd also be good to measure the impact of.
If it's nontrivial, then a likely fix would be:
widget.style
out of the list; only add styles from within the node tree.