calculateTextDirection method
Calculate the text direction of a block component.
Implementation
// defaultTextDirection will be ltr if caller hasn't passed any value.
TextDirection calculateTextDirection({TextDirection? layoutDirection}) {
layoutDirection ??= TextDirection.ltr;
final defaultTextDirection = editorState.editorStyle.defaultTextDirection;
final direction = calculateNodeDirection(
node: node,
layoutDirection: layoutDirection,
defaultTextDirection: defaultTextDirection,
lastDirection: lastDirection,
);
// node indent padding is added by parent node and the padding direction
// is equal to the node text direction. when the node direction is auto
// there is a special case which on typing text, the node direction could
// change without any change to parent node, because no attribute of the
// node changes as the direction attribute is auto but the calculated can
// change to rtl or ltr. in this cases we should notify parent node to
// recalculate the indent padding.
if (node.level > 1 &&
direction != lastDirection &&
node.direction(defaultTextDirection) ==
blockComponentTextDirectionAuto) {
WidgetsBinding.instance
.addPostFrameCallback((_) => node.parent?.notify());
}
lastDirection = direction;
return direction;
}