Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fixed an issue where bullet points became visually detached from the text body when toggling text direction formatting (RTL) by locking the list leading block to the editor's base text direction.
- Fixed typed text being inserted at the previous caret position on Android after moving the caret with a tap/mouse by keeping the platform IME's editing state in sync with the selection even when the keyboard is hidden.
- Fixed the editor's intrinsic size adding the trailing padding instead of subtracting it, which made `IntrinsicHeight`/`IntrinsicWidth` measure the content at the undeflated size and overflow by one line at the exact moment a line wraps.

### Removed

Expand Down
8 changes: 4 additions & 4 deletions lib/src/editor/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1850,7 +1850,7 @@ class RenderEditableContainerBox extends RenderBox
return _getIntrinsicCrossAxis((child) {
final childHeight = math.max<double>(
0,
height - _resolvedPadding!.top + _resolvedPadding!.bottom,
height - _resolvedPadding!.vertical,
);
return child.getMinIntrinsicWidth(childHeight) +
_resolvedPadding!.left +
Expand All @@ -1864,7 +1864,7 @@ class RenderEditableContainerBox extends RenderBox
return _getIntrinsicCrossAxis((child) {
final childHeight = math.max<double>(
0,
height - _resolvedPadding!.top + _resolvedPadding!.bottom,
height - _resolvedPadding!.vertical,
);
return child.getMaxIntrinsicWidth(childHeight) +
_resolvedPadding!.left +
Expand All @@ -1878,7 +1878,7 @@ class RenderEditableContainerBox extends RenderBox
return _getIntrinsicMainAxis((child) {
final childWidth = math.max<double>(
0,
width - _resolvedPadding!.left + _resolvedPadding!.right,
width - _resolvedPadding!.horizontal,
);
return child.getMinIntrinsicHeight(childWidth) +
_resolvedPadding!.top +
Expand All @@ -1892,7 +1892,7 @@ class RenderEditableContainerBox extends RenderBox
return _getIntrinsicMainAxis((child) {
final childWidth = math.max<double>(
0,
width - _resolvedPadding!.left + _resolvedPadding!.right,
width - _resolvedPadding!.horizontal,
);
return child.getMaxIntrinsicHeight(childWidth) +
_resolvedPadding!.top +
Expand Down
59 changes: 59 additions & 0 deletions test/bug_fix_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,63 @@ void main() {
);
},
);

group('2748 - RenderEditableContainerBox intrinsics add trailing padding '
'instead of subtracting it', () {
testWidgets(
'intrinsic height matches laid-out height with horizontal padding',
(tester) async {
const editorWidth = 400.0;
const padding = EdgeInsets.symmetric(horizontal: 100, vertical: 10);

// Measure the test font's glyph advance, then build a single word
// sized to fill one full editor width: it fits on one line at the
// undeflated width (the buggy intrinsic measure) but must wrap once
// laid out at the padding-deflated width.
final glyphPainter = TextPainter(
text: const TextSpan(text: 'a', style: TextStyle(fontSize: 16)),
textDirection: TextDirection.ltr,
)..layout();
final word = 'a' * (editorWidth ~/ glyphPainter.width);

final controller = QuillController.basic()..document.insert(0, word);

await tester.pumpWidget(
QuillTestApp.withScaffold(
Align(
alignment: Alignment.topLeft,
child: SizedBox(
width: editorWidth,
child: QuillEditor.basic(
controller: controller,
config: const QuillEditorConfig(padding: padding),
),
),
),
),
);

final renderEditor = tester.allRenderObjects
.whereType<RenderEditor>()
.single;
final laidOutHeight = renderEditor.size.height;

// Guard: the word must actually wrap at the deflated width,
// otherwise the intrinsic and layout widths are indistinguishable.
expect(
laidOutHeight,
greaterThan(padding.vertical + glyphPainter.height * 1.5),
);

expect(
renderEditor.getMaxIntrinsicHeight(editorWidth),
moreOrLessEquals(laidOutHeight),
);
expect(
renderEditor.getMinIntrinsicHeight(editorWidth),
moreOrLessEquals(laidOutHeight),
);
},
);
});
}