Repository navigation
feat!: Use Flutter's paragraph layout for rich text documents - #4064
Merged
Merged
Conversation
spydon
marked this pull request as ready for review
September 28, 2026 20:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The rich text document pipeline (
DocumentRoot,ParagraphNode,HeaderNode, and thereforeflame_markdown) was the last place in Flame that broke lines itself. Its layout builder split on ASCII spaces, re-measured every tentative line with a freshTextPainter, could not wrap CJK, threw onTextAlign.justify, lost kerning and ligatures at span boundaries, and needed glue heuristics for punctuation that were patched again in #4060 after #3192 and #3939.Since
InlineTextStylealways renders throughTextPaint, that pipeline can hand the whole block to Flutter's paragraph engine without losing any capability:InlineTextNode.layoutBuilderis replaced byInlineSpan toInlineSpan().PlainTextNodeandGroupTextNodebuild aTextSpantree, the wrapper nodes delegate to their child.TextBlockNode.formatlays out oneTextPainterper block and returns the newParagraphTextElement, which exposeslinesandlineMetrics. Justify, CJK wrapping, hard line breaks, and shaping across differently styled spans now work.TextElementgained a no-opdispose(), forwarded byGroupElement, whichParagraphTextElementuses to release its painter.TextBoxComponentlays out a dedicated painter for wrapping and reads lines throughParagraphTextElement. It previously calledlayout(maxWidth:)on the painter shared through theTextPaintcache, so the wrapped layout leaked into laterformatcalls for the same string. Per-line rendering,align,growingBoxand the typewriter effect are unchanged.Checklist
docsand added dartdoc comments with///.examplesordocs.Breaking Change?
Migration instructions
TextNodeLayoutBuilderandInlineTextNode.layoutBuilderare removed. CustomInlineTextNodesubclasses implementInlineSpan toInlineSpan()instead, returning aTextSpanbuilt fromstyle.asTextStyle().GroupTextElementis removed. A text block now yields a singleParagraphTextElementinstead of one inline element per line. Use itslinesorlineMetricsto inspect the line breaking.Related Issues
Follow-up to #4060, which deferred reusing Flutter's layout algorithm.