@@ -38,29 +38,37 @@ void CBaseTextShadowNode::buildAttributedString( // EDITED
3838 auto fragment = AttributedString::Fragment{};
3939 fragment.string = paragraphParentNode->getConcreteProps ().text ;
4040 fragment.textAttributes = baseTextAttributes;
41- outAttributedString.appendFragment (fragment);
41+ outAttributedString.appendFragment (std::move ( fragment) );
4242 return ;
4343 }
4444 // END ADDED
45-
45+ bool lastFragmentWasRawText = false ;
4646 for (const auto & childNode : parentNode.getChildren ()) {
4747 // RawShadowNode
4848 auto rawTextShadowNode =
4949 dynamic_cast <const RawTextShadowNode*>(childNode.get ());
5050 if (rawTextShadowNode != nullptr ) {
51- auto fragment = AttributedString::Fragment{};
52- fragment.string = rawTextShadowNode->getConcreteProps ().text ;
53- fragment.textAttributes = baseTextAttributes;
51+ const auto & rawText = rawTextShadowNode->getConcreteProps ().text ;
52+ if (lastFragmentWasRawText) {
53+ outAttributedString.getFragments ().back ().string += rawText;
54+ } else {
55+ auto fragment = AttributedString::Fragment{};
56+ fragment.string = rawText;
57+ fragment.textAttributes = baseTextAttributes;
5458
55- // Storing a retaining pointer to `ParagraphShadowNode` inside
56- // `attributedString` causes a retain cycle (besides that fact that we
57- // don't need it at all). Storing a `ShadowView` instance instead of
58- // `ShadowNode` should properly fix this problem.
59- fragment.parentShadowView = shadowViewFromShadowNode (parentNode);
60- outAttributedString.appendFragment (fragment);
59+ // Storing a retaining pointer to `ParagraphShadowNode` inside
60+ // `attributedString` causes a retain cycle (besides that fact that we
61+ // don't need it at all). Storing a `ShadowView` instance instead of
62+ // `ShadowNode` should properly fix this problem.
63+ fragment.parentShadowView = shadowViewFromShadowNode (parentNode);
64+ outAttributedString.appendFragment (std::move (fragment));
65+ lastFragmentWasRawText = true ;
66+ }
6167 continue ;
6268 }
6369
70+ lastFragmentWasRawText = false ;
71+
6472 // TextShadowNode
6573 auto textShadowNode = dynamic_cast <const TextShadowNode*>(childNode.get ());
6674 if (textShadowNode != nullptr ) {
@@ -80,7 +88,7 @@ void CBaseTextShadowNode::buildAttributedString( // EDITED
8088 fragment.string = AttributedString::Fragment::AttachmentCharacter ();
8189 fragment.parentShadowView = shadowViewFromShadowNode (*childNode);
8290 fragment.textAttributes = baseTextAttributes;
83- outAttributedString.appendFragment (fragment);
91+ outAttributedString.appendFragment (std::move ( fragment) );
8492 outAttachments.push_back (Attachment{
8593 childNode.get (), outAttributedString.getFragments ().size () - 1 });
8694 }
0 commit comments