[Hoàng Sang] When the number list is too large, numbers will be lost (#1373)

pull/1376/head
Phạm Hoàng Sang 2 years ago committed by GitHub
parent 2045d45e88
commit 04fc2e2f9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      lib/src/widgets/text_block.dart

@ -152,7 +152,7 @@ class EditableTextBlock extends StatelessWidget {
onLaunchUrl: onLaunchUrl, onLaunchUrl: onLaunchUrl,
customLinkPrefixes: customLinkPrefixes, customLinkPrefixes: customLinkPrefixes,
), ),
_getIndentWidth(context), _getIndentWidth(context, count),
_getSpacingForLine(line, index, count, defaultStyles), _getSpacingForLine(line, index, count, defaultStyles),
textDirection, textDirection,
textSelection, textSelection,
@ -168,6 +168,20 @@ class EditableTextBlock extends StatelessWidget {
return children.toList(growable: false); return children.toList(growable: false);
} }
double _numberPointWidth(double fontSize, int count) {
final length = '$count'.length;
switch (length) {
case 1:
case 2:
return fontSize * 2;
default:
// 3 -> 2.5
// 4 -> 3
// 5 -> 3.5
return fontSize * (length - (length - 2) / 2);
}
}
Widget? _buildLeading(BuildContext context, Line line, int index, Widget? _buildLeading(BuildContext context, Line line, int index,
Map<int, int> indentLevelCounts, int count) { Map<int, int> indentLevelCounts, int count) {
final defaultStyles = QuillStyles.getStyles(context, false)!; final defaultStyles = QuillStyles.getStyles(context, false)!;
@ -181,7 +195,7 @@ class EditableTextBlock extends StatelessWidget {
count: count, count: count,
style: defaultStyles.leading!.style, style: defaultStyles.leading!.style,
attrs: attrs, attrs: attrs,
width: fontSize * 2, width: _numberPointWidth(fontSize, count),
padding: fontSize / 2, padding: fontSize / 2,
); );
} }
@ -222,7 +236,7 @@ class EditableTextBlock extends StatelessWidget {
count: count, count: count,
style: defaultStyles.code!.style style: defaultStyles.code!.style
.copyWith(color: defaultStyles.code!.style.color!.withOpacity(0.4)), .copyWith(color: defaultStyles.code!.style.color!.withOpacity(0.4)),
width: fontSize * 2, width: _numberPointWidth(fontSize, count),
attrs: attrs, attrs: attrs,
padding: fontSize, padding: fontSize,
withDot: false, withDot: false,
@ -231,7 +245,7 @@ class EditableTextBlock extends StatelessWidget {
return null; return null;
} }
double _getIndentWidth(BuildContext context) { double _getIndentWidth(BuildContext context, int count) {
final defaultStyles = QuillStyles.getStyles(context, false)!; final defaultStyles = QuillStyles.getStyles(context, false)!;
final fontSize = defaultStyles.paragraph?.style.fontSize ?? 16; final fontSize = defaultStyles.paragraph?.style.fontSize ?? 16;
final attrs = block.style.attributes; final attrs = block.style.attributes;
@ -248,9 +262,13 @@ class EditableTextBlock extends StatelessWidget {
var baseIndent = 0.0; var baseIndent = 0.0;
if (attrs.containsKey(Attribute.list.key) || if (attrs.containsKey(Attribute.list.key)) {
attrs.containsKey(Attribute.codeBlock.key)) {
baseIndent = fontSize * 2; baseIndent = fontSize * 2;
if (attrs[Attribute.list.key] == Attribute.ol) {
baseIndent = _numberPointWidth(fontSize, count);
} else if (attrs.containsKey(Attribute.codeBlock.key)) {
baseIndent = _numberPointWidth(fontSize, count);
}
} }
return baseIndent + extraIndent; return baseIndent + extraIndent;

Loading…
Cancel
Save