Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.8

- **FIXED**: Invalidate and relayout render object after system fonts changed.

## 0.0.7

- **FIXED**: Preserved indentation on line breaks within list items [#4].
Expand All @@ -7,7 +11,7 @@

## 0.0.6

- **FIXED**: Fixed escaping of special characters. [#6]
- **FIXED**: Fixed escaping of special characters. [#6]

## 0.0.5

Expand Down
26 changes: 25 additions & 1 deletion lib/src/render.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,19 @@ class MarkdownRenderObject extends RenderBox {
_painter.handleEvent(event);
}

/// Handles system font changes by marking the render object as needing layout
void _handleSystemFontsChange() {
// Invalidate cached layouts in painter and all block painters
_painter.invalidateLayout();
// Request new layout and paint
markNeedsLayout();
}

@override
// ignore: unnecessary_overrides
void attach(PipelineOwner owner) {
super.attach(owner);
// Ensure the painter is mounted when the render object is attached.
PaintingBinding.instance.systemFonts.addListener(_handleSystemFontsChange);
}

/// Updates the render object with a new values.
Expand All @@ -124,6 +132,8 @@ class MarkdownRenderObject extends RenderBox {
@override
@protected
void detach() {
PaintingBinding.instance.systemFonts
.removeListener(_handleSystemFontsChange);
super.detach();
}

Expand Down Expand Up @@ -264,6 +274,20 @@ class MarkdownPainter {
return true; // Indicate that the painter was updated.
}

/// Invalidate cached layouts when system fonts change.
/// This forces TextPainters to recreate their layouts with new fonts.
void invalidateLayout() {
_needsLayout = true;
_lastSize = null;
_lastPicture = null;
// Dispose and rebuild all block painters to recreate TextPainters
// with the new system fonts
for (final painter in _blockPainters) {
painter.dispose();
}
_rebuild();
}

/// Layouts the markdown content with the given width.
Size layout({required double maxWidth}) {
if (_isEmpty) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description: >
Markdown library written in Dart.
It can parse and display Markdown.

version: 0.0.7
version: 0.0.8

homepage: https://github.com/DoctorinaAI/md
repository: https://github.com/DoctorinaAI/md
Expand Down