-
Notifications
You must be signed in to change notification settings - Fork 210
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
Conversation
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 ReportPatch coverage:
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
☔ View full report in Codecov by Sentry. |
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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; | |
} |
final direction = _determineTextDirection(text); | ||
if (direction != null) { | ||
return direction; | ||
} | ||
|
||
return defaultTextDirection?.toTextDirection() ?? layoutDirection; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final direction = _determineTextDirection(text); | |
if (direction != null) { | |
return direction; | |
} | |
return defaultTextDirection?.toTextDirection() ?? layoutDirection; | |
return _determineTextDirection(text) ?? | |
defaultTextDirection?.toTextDirection() ?? | |
layoutDirection; |
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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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(); | |
} | |
} |
extension on Node { | ||
String? direction(String? defaultDirection) { | ||
return (attributes[blockComponentTextDirection] as String?) ?? | ||
defaultDirection; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
final firstChild = node.children.first; | ||
final currentState = | ||
firstChild.key.currentState as BlockComponentTextDirectionMixin?; | ||
if (currentState != null) { |
There was a problem hiding this comment.
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.
No description provided.