fix(app): study faces centred in the card

The read-only view passed its alignment to the text alone, which the
editor lays out only as wide as itself, so a centred face stayed at the
start. It now aligns top-level paragraphs and headings that have no
alignment of their own; lists, quotes and the rest keep the start, and
an alignment chosen in the format bar wins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
Tizian 「ティツィアーン」 2026-10-08 14:14:39 +02:00
commit 7c00abcc05
Signed by: raisondetredev
GPG key ID: 07F6FCF405488B64

View file

@ -74,4 +74,83 @@ void main() {
expect(tapped, 1);
expect(tester.testTextInput.hasAnyClients, isFalse);
}, variant: TargetPlatformVariant.all());
group('asked to centre', () {
Map<String, Object?> block(
String type,
String text, [
Map<String, Object?> data = const {},
]) => {
'type': type,
'data': {
...data,
'delta': [
{'insert': text},
],
},
};
Future<void> showCentred(
WidgetTester tester,
List<Map<String, Object?>> blocks,
) async {
tester.view.physicalSize = const Size(400, 800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(
MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
home: Scaffold(
body: ListView(
children: [
RichContentView(
content: RichContent({
'document': {'type': 'page', 'children': blocks},
}),
textAlign: TextAlign.center,
),
],
),
),
),
);
await tester.pump(const Duration(seconds: 1));
}
double centreOf(WidgetTester tester, String text) =>
tester.getCenter(find.text(text, findRichText: true)).dx;
double leftOf(WidgetTester tester, String text) =>
tester.getTopLeft(find.text(text, findRichText: true)).dx;
testWidgets('centres paragraphs and headings', (tester) async {
await showCentred(tester, [
block('heading', 'Greetings', {'level': 2}),
block('paragraph', 'hola'),
]);
expect(centreOf(tester, 'Greetings'), moreOrLessEquals(200, epsilon: 1));
expect(centreOf(tester, 'hola'), moreOrLessEquals(200, epsilon: 1));
});
testWidgets('leaves a list at the start: centred, its markers would '
'drift apart', (tester) async {
await showCentred(tester, [
block('bulleted_list', 'hola'),
block('bulleted_list', 'buenos días'),
]);
expect(leftOf(tester, 'hola'), lessThan(60));
expect(leftOf(tester, 'buenos días'), leftOf(tester, 'hola'));
});
testWidgets('keeps the alignment a paragraph was given in the editor', (
tester,
) async {
await showCentred(tester, [
block('paragraph', 'hola', {'align': 'left'}),
]);
expect(leftOf(tester, 'hola'), lessThan(40));
});
});
}