Skip to content

Commit

Permalink
opt.: code builder
Browse files Browse the repository at this point in the history
  • Loading branch information
lollipopkit committed Mar 21, 2024
1 parent 163c089 commit 40ab0f2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/view/page/home/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class _ChatPageState extends State<_ChatPage>
extensionSet: MarkdownUtils.extensionSet,
onTapLink: MarkdownUtils.onLinkTap,
shrinkWrap: false,
fitContent: false,
fitContent: true,

/// User experience is better when this is false.
selectable: false,
Expand Down
14 changes: 13 additions & 1 deletion lib/view/widget/code.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class CodeElementBuilder extends MarkdownElementBuilder {

CodeElementBuilder({this.onCopy, this.isForCapture = false});

static final _bgPaint = Paint()
..color = const Color.fromARGB(28, 159, 159, 159);

@override
Widget? visitElementAfter(md.Element element, TextStyle? preferredStyle) {
// Can't be null
Expand All @@ -26,7 +29,16 @@ class CodeElementBuilder extends MarkdownElementBuilder {

final textContent = element.textContent.trim();
if (language.isEmpty) {
return null;
return RichText(
text: TextSpan(
text: textContent,
style: _textStyle.copyWith(
color: preferredStyle?.color,
background: _bgPaint,
),
),
softWrap: false,
);
}

// if (language == 'latex') {
Expand Down

0 comments on commit 40ab0f2

Please sign in to comment.