From 856617046851896074b7ca235478ca8ef251d9e7 Mon Sep 17 00:00:00 2001 From: Shubham Gupta Date: Mon, 8 Jul 2024 09:59:43 +0530 Subject: [PATCH] fix: Fixed passing textStyle to formula embed (#1989) --- lib/src/widgets/quill/text_line.dart | 34 ++++++++++++++++------------ 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/src/widgets/quill/text_line.dart b/lib/src/widgets/quill/text_line.dart index b802d1fb..c3dbb146 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( @@ -377,8 +387,8 @@ class _TextLineState extends State { final isLink = nodeStyle.containsKey(Attribute.link.key) && nodeStyle.attributes[Attribute.link.key]!.value != null; - final style = _getInlineTextStyle( - textNode, defaultStyles, nodeStyle, lineStyle, isLink); + final style = + _getInlineTextStyle(nodeStyle, defaultStyles, lineStyle, isLink); if (widget.controller.configurations.requireScriptFontFeatures == false && textNode.value.isNotEmpty) { @@ -400,14 +410,10 @@ class _TextLineState extends State { ); } - TextStyle _getInlineTextStyle( - leaf.QuillText textNode, - DefaultStyles defaultStyles, - Style nodeStyle, - Style lineStyle, - bool isLink) { + TextStyle _getInlineTextStyle(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 +452,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 +488,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; }