Skip to content

Commit 1c51779

Browse files
authored
aligns numerical and bullet lists along with text content (singerdmx#1054)
1 parent 12bafd8 commit 1c51779

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

lib/src/widgets/text_block.dart

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ class EditableTextBlock extends StatelessWidget {
135135
_buildLeading(context, line, index, indentLevelCounts, count),
136136
TextLine(
137137
line: line,
138+
index: index,
138139
textDirection: textDirection,
139140
embedBuilder: embedBuilder,
140141
customStyleBuilder: customStyleBuilder,
@@ -164,25 +165,6 @@ class EditableTextBlock extends StatelessWidget {
164165
Map<int, int> indentLevelCounts, int count) {
165166
final defaultStyles = QuillStyles.getStyles(context, false);
166167
final attrs = line.style.attributes;
167-
if (attrs[Attribute.list.key] == Attribute.ol) {
168-
return QuillNumberPoint(
169-
index: index,
170-
indentLevelCounts: indentLevelCounts,
171-
count: count,
172-
style: defaultStyles!.leading!.style,
173-
attrs: attrs,
174-
width: 32,
175-
padding: 8,
176-
);
177-
}
178-
179-
if (attrs[Attribute.list.key] == Attribute.ul) {
180-
return QuillBulletPoint(
181-
style:
182-
defaultStyles!.leading!.style.copyWith(fontWeight: FontWeight.bold),
183-
width: 32,
184-
);
185-
}
186168

187169
if (attrs[Attribute.list.key] == Attribute.checked) {
188170
return CheckboxPoint(
@@ -235,8 +217,7 @@ class EditableTextBlock extends StatelessWidget {
235217

236218
var baseIndent = 0.0;
237219

238-
if (attrs.containsKey(Attribute.list.key) ||
239-
attrs.containsKey(Attribute.codeBlock.key)) {
220+
if (attrs.containsKey(Attribute.codeBlock.key)) {
240221
baseIndent = 32.0;
241222
}
242223

lib/src/widgets/text_line.dart

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ class TextLine extends StatefulWidget {
3838
required this.controller,
3939
required this.onLaunchUrl,
4040
required this.linkActionPicker,
41+
this.index,
4142
this.textDirection,
4243
this.customStyleBuilder,
4344
Key? key,
4445
}) : super(key: key);
4546

4647
final Line line;
48+
final int? index;
4749
final TextDirection? textDirection;
4850
final EmbedsBuilder embedBuilder;
4951
final DefaultStyles styles;
@@ -294,9 +296,22 @@ class _TextLineState extends State<TextLine> {
294296
final nodeStyle = textNode.style;
295297
final isLink = nodeStyle.containsKey(Attribute.link.key) &&
296298
nodeStyle.attributes[Attribute.link.key]!.value != null;
299+
final attrs = widget.line.style.attributes;
300+
const whiteSpace = TextSpan(text: ' ');
301+
302+
var leading = const TextSpan();
303+
if (attrs[Attribute.list.key] == Attribute.ol) {
304+
leading = TextSpan(text: '${widget.index.toString()}.');
305+
} else if (attrs[Attribute.list.key] == Attribute.ul) {
306+
leading = TextSpan(
307+
text: '•',
308+
style:
309+
defaultStyles.leading!.style.copyWith(fontWeight: FontWeight.bold),
310+
);
311+
}
297312

298313
return TextSpan(
299-
text: textNode.value,
314+
children: [leading, whiteSpace, TextSpan(text: textNode.value)],
300315
style: _getInlineTextStyle(
301316
textNode, defaultStyles, nodeStyle, lineStyle, isLink),
302317
recognizer: isLink && canLaunchLinks ? _getRecognizer(node) : null,

0 commit comments

Comments
 (0)