From 030007159daa62e0ff64e30a7f833ba4aa4b7350 Mon Sep 17 00:00:00 2001 From: nyne Date: Tue, 31 Dec 2024 13:56:11 +0800 Subject: [PATCH] fix editor font --- lib/components/code.dart | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/components/code.dart b/lib/components/code.dart index e72ae16..0f3f02e 100644 --- a/lib/components/code.dart +++ b/lib/components/code.dart @@ -67,10 +67,6 @@ class _CodeEditorState extends State { child: IntrinsicWidth( stepWidth: 100, child: TextField( - style: TextStyle( - fontFamily: 'consolas', - fontFamilyFallback: ['Courier New', 'monospace'], - ), controller: _controller, focusNode: _focusNode, maxLines: null, @@ -124,6 +120,20 @@ class _CodeTextEditingController extends TextEditingController { theme: _theme!, ); var result = highlighter.highlight(text); + style = TextStyle( + fontFamily: 'consolas', + fontFamilyFallback: ['Courier New', 'monospace'], + ); + + return setTextSpanFont(result, style); + } + + TextSpan setTextSpanFont(TextSpan span, TextStyle style) { + var result = TextSpan( + style: style.merge(span.style), + children: span.children?.whereType().map((e) => setTextSpanFont(e, style)).toList(), + text: span.text, + ); return result; } }