@@ -9,6 +9,7 @@ import 'package:super_editor/src/core/editor.dart';
9
9
import 'package:super_editor/src/core/styles.dart' ;
10
10
import 'package:super_editor/src/default_editor/attributions.dart' ;
11
11
import 'package:super_editor/src/default_editor/blocks/indentation.dart' ;
12
+ import 'package:super_editor/src/default_editor/text_tools.dart' ;
12
13
import 'package:super_editor/src/infrastructure/_logging.dart' ;
13
14
import 'package:super_editor/src/infrastructure/attributed_text_styles.dart' ;
14
15
import 'package:super_editor/src/infrastructure/keyboard.dart' ;
@@ -161,11 +162,16 @@ class ListItemComponentBuilder implements ComponentBuilder {
161
162
ordinalValue = computeListItemOrdinalValue (node, document);
162
163
}
163
164
165
+ final textDirection = getParagraphDirection (node.text.toPlainText ());
166
+ final textAlignment = textDirection == TextDirection .ltr ? TextAlign .left : TextAlign .right;
167
+
164
168
return switch (node.type) {
165
169
ListItemType .unordered => UnorderedListItemComponentViewModel (
166
170
nodeId: node.id,
167
171
indent: node.indent,
168
172
text: node.text,
173
+ textDirection: textDirection,
174
+ textAlignment: textAlignment,
169
175
textStyleBuilder: noStyleBuilder,
170
176
selectionColor: const Color (0x00000000 ),
171
177
),
@@ -174,6 +180,8 @@ class ListItemComponentBuilder implements ComponentBuilder {
174
180
indent: node.indent,
175
181
ordinalValue: ordinalValue,
176
182
text: node.text,
183
+ textDirection: textDirection,
184
+ textAlignment: textAlignment,
177
185
textStyleBuilder: noStyleBuilder,
178
186
selectionColor: const Color (0x00000000 ),
179
187
),
@@ -196,6 +204,8 @@ class ListItemComponentBuilder implements ComponentBuilder {
196
204
indent: componentViewModel.indent,
197
205
dotStyle: componentViewModel.dotStyle,
198
206
textSelection: componentViewModel.selection,
207
+ textDirection: componentViewModel.textDirection,
208
+ textAlignment: componentViewModel.textAlignment,
199
209
selectionColor: componentViewModel.selectionColor,
200
210
highlightWhenEmpty: componentViewModel.highlightWhenEmpty,
201
211
underlines: componentViewModel.createUnderlines (),
@@ -206,6 +216,8 @@ class ListItemComponentBuilder implements ComponentBuilder {
206
216
indent: componentViewModel.indent,
207
217
listIndex: componentViewModel.ordinalValue! ,
208
218
text: componentViewModel.text,
219
+ textDirection: componentViewModel.textDirection,
220
+ textAlignment: componentViewModel.textAlignment,
209
221
styleBuilder: componentViewModel.textStyleBuilder,
210
222
numeralStyle: componentViewModel.numeralStyle,
211
223
textSelection: componentViewModel.selection,
@@ -281,6 +293,7 @@ abstract class ListItemComponentViewModel extends SingleColumnLayoutComponentVie
281
293
indent == other.indent &&
282
294
text == other.text &&
283
295
textDirection == other.textDirection &&
296
+ textAlignment == other.textAlignment &&
284
297
selection == other.selection &&
285
298
selectionColor == other.selectionColor &&
286
299
highlightWhenEmpty == other.highlightWhenEmpty &&
@@ -298,6 +311,7 @@ abstract class ListItemComponentViewModel extends SingleColumnLayoutComponentVie
298
311
indent.hashCode ^
299
312
text.hashCode ^
300
313
textDirection.hashCode ^
314
+ textAlignment.hashCode ^
301
315
selection.hashCode ^
302
316
selectionColor.hashCode ^
303
317
highlightWhenEmpty.hashCode ^
@@ -355,6 +369,7 @@ class UnorderedListItemComponentViewModel extends ListItemComponentViewModel {
355
369
textStyleBuilder: textStyleBuilder,
356
370
dotStyle: dotStyle,
357
371
textDirection: textDirection,
372
+ textAlignment: textAlignment,
358
373
selection: selection,
359
374
selectionColor: selectionColor,
360
375
composingRegion: composingRegion,
@@ -423,6 +438,7 @@ class OrderedListItemComponentViewModel extends ListItemComponentViewModel {
423
438
text: text,
424
439
textStyleBuilder: textStyleBuilder,
425
440
textDirection: textDirection,
441
+ textAlignment: textAlignment,
426
442
selection: selection,
427
443
selectionColor: selectionColor,
428
444
composingRegion: composingRegion,
@@ -493,6 +509,8 @@ class UnorderedListItemComponent extends StatefulWidget {
493
509
Key ? key,
494
510
required this .componentKey,
495
511
required this .text,
512
+ this .textDirection = TextDirection .ltr,
513
+ this .textAlignment = TextAlign .left,
496
514
required this .styleBuilder,
497
515
this .inlineWidgetBuilders = const [],
498
516
this .dotBuilder = _defaultUnorderedListItemDotBuilder,
@@ -510,6 +528,8 @@ class UnorderedListItemComponent extends StatefulWidget {
510
528
511
529
final GlobalKey componentKey;
512
530
final AttributedText text;
531
+ final TextDirection textDirection;
532
+ final TextAlign textAlignment;
513
533
final AttributionStyleBuilder styleBuilder;
514
534
final InlineWidgetBuilderChain inlineWidgetBuilders;
515
535
final UnorderedListItemDotBuilder dotBuilder;
@@ -558,34 +578,39 @@ class _UnorderedListItemComponentState extends State<UnorderedListItemComponent>
558
578
return ProxyTextDocumentComponent (
559
579
key: widget.componentKey,
560
580
textComponentKey: _innerTextComponentKey,
561
- child: Row (
562
- crossAxisAlignment: CrossAxisAlignment .start,
563
- children: [
564
- Container (
565
- width: indentSpace,
566
- decoration: BoxDecoration (
567
- border: widget.showDebugPaint ? Border .all (width: 1 , color: Colors .grey) : null ,
568
- ),
569
- child: SizedBox (
570
- height: lineHeight,
571
- child: widget.dotBuilder (context, widget),
581
+ child: Directionality (
582
+ textDirection: widget.textDirection,
583
+ child: Row (
584
+ crossAxisAlignment: CrossAxisAlignment .start,
585
+ children: [
586
+ Container (
587
+ width: indentSpace,
588
+ decoration: BoxDecoration (
589
+ border: widget.showDebugPaint ? Border .all (width: 1 , color: Colors .grey) : null ,
590
+ ),
591
+ child: SizedBox (
592
+ height: lineHeight,
593
+ child: widget.dotBuilder (context, widget),
594
+ ),
572
595
),
573
- ),
574
- Expanded (
575
- child: TextComponent (
576
- key: _innerTextComponentKey,
577
- text: widget.text,
578
- textStyleBuilder: widget.styleBuilder,
579
- inlineWidgetBuilders: widget.inlineWidgetBuilders,
580
- textSelection: widget.textSelection,
581
- textScaler: textScaler,
582
- selectionColor: widget.selectionColor,
583
- highlightWhenEmpty: widget.highlightWhenEmpty,
584
- underlines: widget.underlines,
585
- showDebugPaint: widget.showDebugPaint,
596
+ Expanded (
597
+ child: TextComponent (
598
+ key: _innerTextComponentKey,
599
+ text: widget.text,
600
+ textDirection: widget.textDirection,
601
+ textAlign: widget.textAlignment,
602
+ textStyleBuilder: widget.styleBuilder,
603
+ inlineWidgetBuilders: widget.inlineWidgetBuilders,
604
+ textSelection: widget.textSelection,
605
+ textScaler: textScaler,
606
+ selectionColor: widget.selectionColor,
607
+ highlightWhenEmpty: widget.highlightWhenEmpty,
608
+ underlines: widget.underlines,
609
+ showDebugPaint: widget.showDebugPaint,
610
+ ),
586
611
),
587
- ) ,
588
- ] ,
612
+ ] ,
613
+ ) ,
589
614
),
590
615
);
591
616
}
@@ -659,6 +684,8 @@ class OrderedListItemComponent extends StatefulWidget {
659
684
required this .componentKey,
660
685
required this .listIndex,
661
686
required this .text,
687
+ this .textDirection = TextDirection .ltr,
688
+ this .textAlignment = TextAlign .left,
662
689
required this .styleBuilder,
663
690
this .inlineWidgetBuilders = const [],
664
691
this .numeralBuilder = _defaultOrderedListItemNumeralBuilder,
@@ -677,6 +704,8 @@ class OrderedListItemComponent extends StatefulWidget {
677
704
final GlobalKey componentKey;
678
705
final int listIndex;
679
706
final AttributedText text;
707
+ final TextDirection textDirection;
708
+ final TextAlign textAlignment;
680
709
final AttributionStyleBuilder styleBuilder;
681
710
final InlineWidgetBuilderChain inlineWidgetBuilders;
682
711
final OrderedListItemNumeralBuilder numeralBuilder;
@@ -725,35 +754,40 @@ class _OrderedListItemComponentState extends State<OrderedListItemComponent> {
725
754
return ProxyTextDocumentComponent (
726
755
key: widget.componentKey,
727
756
textComponentKey: _innerTextComponentKey,
728
- child: Row (
729
- crossAxisAlignment: CrossAxisAlignment .start,
730
- children: [
731
- Container (
732
- width: indentSpace,
733
- height: lineHeight,
734
- decoration: BoxDecoration (
735
- border: widget.showDebugPaint ? Border .all (width: 1 , color: Colors .grey) : null ,
736
- ),
737
- child: SizedBox (
757
+ child: Directionality (
758
+ textDirection: widget.textDirection,
759
+ child: Row (
760
+ crossAxisAlignment: CrossAxisAlignment .start,
761
+ children: [
762
+ Container (
763
+ width: indentSpace,
738
764
height: lineHeight,
739
- child: widget.numeralBuilder (context, widget),
765
+ decoration: BoxDecoration (
766
+ border: widget.showDebugPaint ? Border .all (width: 1 , color: Colors .grey) : null ,
767
+ ),
768
+ child: SizedBox (
769
+ height: lineHeight,
770
+ child: widget.numeralBuilder (context, widget),
771
+ ),
740
772
),
741
- ),
742
- Expanded (
743
- child: TextComponent (
744
- key: _innerTextComponentKey,
745
- text: widget.text,
746
- textStyleBuilder: widget.styleBuilder,
747
- inlineWidgetBuilders: widget.inlineWidgetBuilders,
748
- textSelection: widget.textSelection,
749
- textScaler: textScaler,
750
- selectionColor: widget.selectionColor,
751
- highlightWhenEmpty: widget.highlightWhenEmpty,
752
- underlines: widget.underlines,
753
- showDebugPaint: widget.showDebugPaint,
773
+ Expanded (
774
+ child: TextComponent (
775
+ key: _innerTextComponentKey,
776
+ text: widget.text,
777
+ textDirection: widget.textDirection,
778
+ textAlign: widget.textAlignment,
779
+ textStyleBuilder: widget.styleBuilder,
780
+ inlineWidgetBuilders: widget.inlineWidgetBuilders,
781
+ textSelection: widget.textSelection,
782
+ textScaler: textScaler,
783
+ selectionColor: widget.selectionColor,
784
+ highlightWhenEmpty: widget.highlightWhenEmpty,
785
+ underlines: widget.underlines,
786
+ showDebugPaint: widget.showDebugPaint,
787
+ ),
754
788
),
755
- ) ,
756
- ] ,
789
+ ] ,
790
+ ) ,
757
791
),
758
792
);
759
793
}
0 commit comments