When the number list is too large, words will be lost

pull/1373/head
Phạm Hoàng Sang 2 years ago
parent 3cf1f81cf5
commit 98dc09b12c
  1. 29
      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,19 @@ class EditableTextBlock extends StatelessWidget {
return children.toList(growable: false); return children.toList(growable: false);
} }
double _numberPointWidth(double fontSize, int count) {
switch ('$count'.length) {
case 2:
return fontSize * 2;
case 3:
return fontSize * 2.5;
case 4:
return fontSize * 3;
default:
return fontSize;
}
}
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 +194,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 +235,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 +244,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 +261,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