Skip to content

Commit

Permalink
feat: move the indent padding calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 committed Jul 19, 2023
1 parent 92c60d8 commit 5054f69
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mixin BlockComponentTextDirectionMixin {
TextDirection calculateTextDirection({
TextDirection? defaultTextDirection,
}) {
defaultTextDirection = defaultTextDirection ?? TextDirection.ltr;
defaultTextDirection ??= TextDirection.ltr;

final direction = calculateNodeDirection(
node: node,
Expand Down Expand Up @@ -50,12 +50,12 @@ mixin BlockComponentTextDirectionMixin {
// If the textDirection attribute is not set we will use defaultTextDirection.
// If the textDirection is ltr or rtl we will apply that.
// If the textDirection is auto we go by these priorities:
// 1. Determine the direction by first charachter with strong directionality
// 1. Determine the direction by first character with strong directionality
// 2. lastDirection which is the node last determined direction
// 3. previous line direction
// 4. defaultTextDirection
// We will move from first priority when for example the node text is empty or
// it only has charachters without strong directionality e.g. '@'.
// it only has characters without strong directionality e.g. '@'.
TextDirection calculateNodeDirection({
required Node node,
required TextDirection defaultTextDirection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,6 @@ class _BulletedListBlockComponentWidgetState
@override
Node get node => widget.node;

@override
EdgeInsets get indentPadding {
TextDirection direction =
Directionality.maybeOf(context) ?? TextDirection.ltr;
if (node.children.isNotEmpty) {
direction = calculateNodeDirection(
node: node.children.first,
defaultTextDirection: direction,
);
}
return configuration.indentPadding(node, direction);
}

@override
Widget buildComponent(BuildContext context) {
final textDirection = calculateTextDirection(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,6 @@ class _NumberedListBlockComponentWidgetState
@override
Node get node => widget.node;

@override
EdgeInsets get indentPadding {
TextDirection direction =
Directionality.maybeOf(context) ?? TextDirection.ltr;
if (node.children.isNotEmpty) {
direction = calculateNodeDirection(
node: node.children.first,
defaultTextDirection: direction,
);
}
return configuration.indentPadding(node, direction);
}

@override
Widget buildComponent(BuildContext context) {
final textDirection = calculateTextDirection(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,6 @@ class _TextBlockComponentWidgetState extends State<TextBlockComponentWidget>
@override
Node get node => widget.node;

@override
EdgeInsets get indentPadding {
TextDirection direction =
Directionality.maybeOf(context) ?? TextDirection.ltr;
if (node.children.isNotEmpty) {
direction = calculateNodeDirection(
node: node.children.first,
defaultTextDirection: direction,
);
}
return configuration.indentPadding(node, direction);
}

@override
Widget buildComponent(BuildContext context) {
final textDirection = calculateTextDirection(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,6 @@ class _TodoListBlockComponentWidgetState
@override
Node get node => widget.node;

@override
EdgeInsets get indentPadding {
TextDirection direction =
Directionality.maybeOf(context) ?? TextDirection.ltr;
if (node.children.isNotEmpty) {
direction = calculateNodeDirection(
node: node.children.first,
defaultTextDirection: direction,
);
}
return configuration.indentPadding(node, direction);
}

bool get checked => widget.node.attributes[TodoListBlockKeys.checked];

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,19 @@ mixin NestedBlockComponentStatefulWidgetMixin<
on State<T>, BlockComponentBackgroundColorMixin {
late final editorState = Provider.of<EditorState>(context, listen: false);

EdgeInsets get indentPadding;
BlockComponentConfiguration get configuration;

EdgeInsets get indentPadding {
TextDirection direction =
Directionality.maybeOf(context) ?? TextDirection.ltr;
if (node.children.isNotEmpty) {
direction = calculateNodeDirection(
node: node.children.first,
defaultTextDirection: direction,
);
}
return configuration.indentPadding(node, direction);
}

double? cachedLeft;

Expand Down

0 comments on commit 5054f69

Please sign in to comment.