From e405612a61f944a8b31755eae24f753e33b58baa Mon Sep 17 00:00:00 2001 From: Shubham Gupta Date: Mon, 8 Jul 2024 09:04:51 +0530 Subject: [PATCH] fix: Resolve textStyle for formula embed --- lib/src/widgets/quill/text_line.dart | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/src/widgets/quill/text_line.dart b/lib/src/widgets/quill/text_line.dart index b802d1fb..25037fcf 100644 --- a/lib/src/widgets/quill/text_line.dart +++ b/lib/src/widgets/quill/text_line.dart @@ -178,7 +178,7 @@ class _TextLineState extends State { } InlineSpan _getTextSpanForWholeLine() { - final lineStyle = _getLineStyle(widget.styles); + var lineStyle = _getLineStyle(widget.styles); if (!widget.line.hasEmbed) { return _buildTextSpan(widget.styles, widget.line.children, lineStyle); } @@ -198,6 +198,16 @@ class _TextLineState extends State { child = Embed(CustomBlockEmbed.fromJsonString(child.value.data)) ..applyStyle(child.style); } + + if (child.value.type == BlockEmbed.formulaType) { + lineStyle = lineStyle.merge(_getInlineTextStyle( + child.style, + widget.styles, + widget.line.style, + false, + )); + } + final embedBuilder = widget.embedBuilder(child); final embedWidget = EmbedProxy( embedBuilder.build( @@ -378,7 +388,7 @@ class _TextLineState extends State { nodeStyle.attributes[Attribute.link.key]!.value != null; final style = _getInlineTextStyle( - textNode, defaultStyles, nodeStyle, lineStyle, isLink); + nodeStyle, defaultStyles, lineStyle, isLink); if (widget.controller.configurations.requireScriptFontFeatures == false && textNode.value.isNotEmpty) { @@ -401,13 +411,12 @@ class _TextLineState extends State { } TextStyle _getInlineTextStyle( - leaf.QuillText textNode, - DefaultStyles defaultStyles, Style nodeStyle, + DefaultStyles defaultStyles, Style lineStyle, bool isLink) { var res = const TextStyle(); // This is inline text style - final color = textNode.style.attributes[Attribute.color.key]; + final color = nodeStyle.attributes[Attribute.color.key]; { Attribute.bold.key: defaultStyles.bold, @@ -446,12 +455,12 @@ class _TextLineState extends State { res = _merge(res, defaultStyles.inlineCode!.styleFor(lineStyle)); } - final font = textNode.style.attributes[Attribute.font.key]; + final font = nodeStyle.attributes[Attribute.font.key]; if (font != null && font.value != null) { res = res.merge(TextStyle(fontFamily: font.value)); } - final size = textNode.style.attributes[Attribute.size.key]; + final size = nodeStyle.attributes[Attribute.size.key]; if (size != null && size.value != null) { switch (size.value) { case 'small': @@ -482,13 +491,13 @@ class _TextLineState extends State { } } - final background = textNode.style.attributes[Attribute.background.key]; + final background = nodeStyle.attributes[Attribute.background.key]; if (background != null && background.value != null) { final backgroundColor = stringToColor(background.value); res = res.merge(TextStyle(backgroundColor: backgroundColor)); } - res = _applyCustomAttributes(res, textNode.style.attributes); + res = _applyCustomAttributes(res, nodeStyle.attributes); return res; }