From 40ab0f2ead99a71c1c6c4e3ae5ed31995760df98 Mon Sep 17 00:00:00 2001 From: lollipopkit Date: Wed, 20 Mar 2024 19:56:53 -0600 Subject: [PATCH] opt.: code builder --- lib/view/page/home/chat.dart | 2 +- lib/view/widget/code.dart | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/view/page/home/chat.dart b/lib/view/page/home/chat.dart index c85e0fc..fb13aae 100644 --- a/lib/view/page/home/chat.dart +++ b/lib/view/page/home/chat.dart @@ -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, diff --git a/lib/view/widget/code.dart b/lib/view/widget/code.dart index e1e3fcc..2db8b68 100644 --- a/lib/view/widget/code.dart +++ b/lib/view/widget/code.dart @@ -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 @@ -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') {