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

fix: respect default and last direction on new line and indent #482

Merged
merged 3 commits into from
Sep 20, 2023

Conversation

zoli
Copy link
Contributor

@zoli zoli commented Sep 19, 2023

No description provided.

fix to use previous or parent direction when the editor
default direction is auto. in that case use the calculated text
direction of previous or parent node.
@codecov
Copy link

codecov bot commented Sep 19, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.36% ⚠️

Comparison is base (6699d58) 80.80% compared to head (a389e7f) 80.45%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #482      +/-   ##
==========================================
- Coverage   80.80%   80.45%   -0.36%     
==========================================
  Files         281      281              
  Lines       11635    11763     +128     
==========================================
+ Hits         9402     9464      +62     
- Misses       2233     2299      +66     
Files Changed Coverage Δ
...component/base_component/text_direction_mixin.dart 100.00% <100.00%> (ø)
..._component/rich_text/default_selectable_mixin.dart 95.00% <100.00%> (+0.12%) ⬆️
...onent/service/renderer/block_component_widget.dart 85.00% <100.00%> (+1.21%) ⬆️

... and 21 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 106 to 121
TextDirection? _getDirectionFromPreviousOrParentNode(
Node node,
String? defaultTextDirection,
) {
TextDirection? prevOrParentNodeDirection;
if (node.previous != null) {
prevOrParentNodeDirection =
_getDirectionFromNode(node.previous!, defaultTextDirection);
}
if (node.parent != null && prevOrParentNodeDirection == null) {
prevOrParentNodeDirection =
_getDirectionFromNode(node.parent!, defaultTextDirection);
}

return prevOrParentNodeDirection;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TextDirection? _getDirectionFromPreviousOrParentNode(
Node node,
String? defaultTextDirection,
) {
TextDirection? prevOrParentNodeDirection;
if (node.previous != null) {
prevOrParentNodeDirection =
_getDirectionFromNode(node.previous!, defaultTextDirection);
}
if (node.parent != null && prevOrParentNodeDirection == null) {
prevOrParentNodeDirection =
_getDirectionFromNode(node.parent!, defaultTextDirection);
}
return prevOrParentNodeDirection;
}
TextDirection? _getDirectionFromPreviousOrParentNode(
Node node,
String? defaultTextDirection,
) {
if (node.previous != null) {
return _getDirectionFromNode(node.previous!, defaultTextDirection);
}
if (node.parent != null) {
return _getDirectionFromNode(node.parent!, defaultTextDirection);
}
return null;
}

Comment on lines 98 to 103
final direction = _determineTextDirection(text);
if (direction != null) {
return direction;
}

return defaultTextDirection?.toTextDirection() ?? layoutDirection;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
final direction = _determineTextDirection(text);
if (direction != null) {
return direction;
}
return defaultTextDirection?.toTextDirection() ?? layoutDirection;
return _determineTextDirection(text) ??
defaultTextDirection?.toTextDirection() ??
layoutDirection;

Comment on lines 123 to 140
TextDirection? _getDirectionFromNode(Node node, String? defaultTextDirection) {
String? nodeDirection;
if (defaultTextDirection == blockComponentTextDirectionAuto) {
nodeDirection = blockComponentTextDirectionAuto;
}

nodeDirection = node.direction(nodeDirection);

if (nodeDirection != null) {
if (nodeDirection == blockComponentTextDirectionAuto) {
return node.selectable?.textDirection();
} else {
return nodeDirection.toTextDirection();
}
}

return null;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TextDirection? _getDirectionFromNode(Node node, String? defaultTextDirection) {
String? nodeDirection;
if (defaultTextDirection == blockComponentTextDirectionAuto) {
nodeDirection = blockComponentTextDirectionAuto;
}
nodeDirection = node.direction(nodeDirection);
if (nodeDirection != null) {
if (nodeDirection == blockComponentTextDirectionAuto) {
return node.selectable?.textDirection();
} else {
return nodeDirection.toTextDirection();
}
}
return null;
}
TextDirection? _getDirectionFromNode(Node node, String? defaultTextDirection) {
final nodeDirection = node.direction(
defaultTextDirection == blockComponentTextDirectionAuto
? blockComponentTextDirectionAuto
: null,
);
if (nodeDirection == blockComponentTextDirectionAuto) {
return node.selectable?.textDirection();
} else {
return nodeDirection?.toTextDirection();
}
}

Comment on lines 154 to 157
extension on Node {
String? direction(String? defaultDirection) {
return (attributes[blockComponentTextDirection] as String?) ??
defaultDirection;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
extension on Node {
String? direction(String? defaultDirection) {
return (attributes[blockComponentTextDirection] as String?) ??
defaultDirection;
extension on Node {
String? direction(String? defaultDirection) =>
attributes[blockComponentTextDirection] as String? ?? defaultDirection;

@LucasXu0 LucasXu0 merged commit 189a41f into AppFlowy-IO:main Sep 20, 2023
9 of 10 checks passed
final firstChild = node.children.first;
final currentState =
firstChild.key.currentState as BlockComponentTextDirectionMixin?;
if (currentState != null) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there a case when the currentState is null and we still want to do the calculation?
last direction is optional parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants