Skip to content

Add Fields to Control Uniform Line Height for Span in flutter-quill #2555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/src/editor/widgets/default_styles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ class DefaultStyles {
this.sizeLarge,
this.sizeHuge,
this.palette,
this.forceStrutHeight,
this.leadingOffset,
});

final DefaultTextBlockStyle? h1;
Expand Down Expand Up @@ -286,6 +288,11 @@ class DefaultStyles {
/// Custom palette of colors
final Map<String, Color>? palette;

// 强制设置同高
final bool? forceStrutHeight;
// 基线位置
final double? leadingOffset;

static DefaultStyles getInstance(BuildContext context) {
final themeData = Theme.of(context);
final defaultTextStyle = DefaultTextStyle.of(context);
Expand Down Expand Up @@ -564,6 +571,8 @@ class DefaultStyles {
sizeLarge: other.sizeLarge ?? sizeLarge,
sizeHuge: other.sizeHuge ?? sizeHuge,
palette: other.palette ?? palette,
forceStrutHeight: other.forceStrutHeight ?? forceStrutHeight,
leadingOffset: other.leadingOffset ?? leadingOffset,
);
}
}
8 changes: 6 additions & 2 deletions lib/src/editor/widgets/text/text_line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,12 @@ class _TextLineState extends State<TextLine> {
}
}
final textSpan = _getTextSpanForWholeLine();
final strutStyle =
StrutStyle.fromTextStyle(textSpan.style ?? const TextStyle());
// 增加强制固定行高
final strutStyle = StrutStyle.fromTextStyle(
textSpan.style ?? const TextStyle(),
forceStrutHeight: widget.styles.forceStrutHeight,
leading: widget.styles.leadingOffset,
);
final textAlign = _getTextAlign();
final child = RichText(
key: _richTextKey,
Expand Down