Skip to content
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

feat: support text align in text-based blocks #1002

Merged
merged 1 commit into from
Dec 24, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class BlockComponentConfiguration {
this.textStyle = _textStyle,
this.placeholderTextStyle = _placeholderTextStyle,
this.blockSelectionAreaMargin = _blockSelectionAreaPadding,
this.textAlign = _textAlign,
});

/// The padding of a block component.
Expand Down Expand Up @@ -39,12 +40,19 @@ class BlockComponentConfiguration {
/// The padding of a block selection area.
final EdgeInsets Function(Node node) blockSelectionAreaMargin;

/// The text align of a block component.
///
/// This value is only available for the block with text,
/// e.g. paragraph, heading, quote, to-do list, bulleted list, numbered list
final TextAlign Function(Node node) textAlign;

BlockComponentConfiguration copyWith({
EdgeInsets Function(Node node)? padding,
TextStyle Function(Node node)? textStyle,
String Function(Node node)? placeholderText,
TextStyle Function(Node node)? placeholderTextStyle,
EdgeInsets Function(Node node)? blockSelectionAreaMargin,
TextAlign Function(Node node)? textAlign,
}) {
return BlockComponentConfiguration(
padding: padding ?? this.padding,
Expand All @@ -53,6 +61,7 @@ class BlockComponentConfiguration {
placeholderTextStyle: placeholderTextStyle ?? this.placeholderTextStyle,
blockSelectionAreaMargin:
blockSelectionAreaMargin ?? this.blockSelectionAreaMargin,
textAlign: textAlign ?? this.textAlign,
);
}
}
Expand All @@ -69,6 +78,8 @@ mixin BlockComponentConfigurable<T extends StatefulWidget> on State<T> {

TextStyle get placeholderTextStyle =>
configuration.placeholderTextStyle(node);

TextAlign get textAlign => configuration.textAlign(node);
}

EdgeInsets _padding(Node node) {
Expand Down Expand Up @@ -101,3 +112,7 @@ TextStyle _placeholderTextStyle(Node node) {
EdgeInsets _blockSelectionAreaPadding(Node node) {
return const EdgeInsets.symmetric(vertical: 0.0);
}

TextAlign _textAlign(Node node) {
return TextAlign.left;
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class _BulletedListBlockComponentWidgetState
delegate: this,
node: widget.node,
editorState: editorState,
textAlign: alignment?.toTextAlign,
textAlign: alignment?.toTextAlign ?? textAlign,
placeholderText: placeholderText,
textSpanDecorator: (textSpan) => textSpan.updateTextStyle(
textStyle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class _HeadingBlockComponentWidgetState
delegate: this,
node: widget.node,
editorState: editorState,
textAlign: alignment?.toTextAlign,
textAlign: alignment?.toTextAlign ?? textAlign,
textSpanDecorator: (textSpan) {
var result = textSpan.updateTextStyle(textStyle);
result = result.updateTextStyle(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class _NumberedListBlockComponentWidgetState
delegate: this,
node: widget.node,
editorState: editorState,
textAlign: alignment?.toTextAlign,
textAlign: alignment?.toTextAlign ?? textAlign,
placeholderText: placeholderText,
textSpanDecorator: (textSpan) => textSpan.updateTextStyle(
textStyle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class _ParagraphBlockComponentWidgetState
delegate: this,
node: widget.node,
editorState: editorState,
textAlign: alignment?.toTextAlign,
textAlign: alignment?.toTextAlign ?? textAlign,
placeholderText: _showPlaceholder ? placeholderText : ' ',
textSpanDecorator: (textSpan) =>
textSpan.updateTextStyle(textStyle),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class _QuoteBlockComponentWidgetState extends State<QuoteBlockComponentWidget>
delegate: this,
node: widget.node,
editorState: editorState,
textAlign: alignment?.toTextAlign,
textAlign: alignment?.toTextAlign ?? textAlign,
placeholderText: placeholderText,
textSpanDecorator: (textSpan) => textSpan.updateTextStyle(
textStyle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class _TodoListBlockComponentWidgetState
delegate: this,
node: widget.node,
editorState: editorState,
textAlign: alignment?.toTextAlign,
textAlign: alignment?.toTextAlign ?? textAlign,
placeholderText: placeholderText,
textDirection: textDirection,
textSpanDecorator: (textSpan) =>
Expand Down
Loading