Skip to content

Commit

Permalink
Fix: direction has no opposite effect is the language is rtl (#2154)
Browse files Browse the repository at this point in the history
  • Loading branch information
CatHood0 authored Aug 27, 2024
1 parent b95dcd9 commit 8dc294c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
7 changes: 5 additions & 2 deletions lib/src/delta/delta_diff.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,12 @@ int getPositionDelta(Delta user, Delta actual) {
return diff;
}

TextDirection getDirectionOfNode(Node node) {
TextDirection getDirectionOfNode(Node node, [TextDirection? currentDirection]) {
final direction = node.style.attributes[Attribute.direction.key];
if (direction == Attribute.rtl) {
// If it is RTL, then create the opposite direction
if (currentDirection == TextDirection.rtl && direction == Attribute.rtl) {
return TextDirection.ltr;
} else if (direction == Attribute.rtl) {
return TextDirection.rtl;
}
return TextDirection.ltr;
Expand Down
10 changes: 1 addition & 9 deletions lib/src/editor/raw_editor/raw_editor_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -975,15 +975,7 @@ class QuillRawEditorState extends EditorState
}

prevNodeOl = attrs[Attribute.list.key] == Attribute.ol;
var nodeTextDirection = getDirectionOfNode(node);
// verify if the direction from nodeTextDirection is the default direction
// and watch if the system language is a RTL language and avoid putting
// to the edge of the left side any checkbox or list point/number if is a
// RTL language
if (nodeTextDirection == TextDirection.ltr &&
_textDirection == TextDirection.rtl) {
nodeTextDirection = TextDirection.rtl;
}
final nodeTextDirection = getDirectionOfNode(node, _textDirection);
if (node is Line) {
final editableTextLine = _getEditableTextLineFromNode(node, context);
result.add(Directionality(
Expand Down
10 changes: 1 addition & 9 deletions lib/src/editor/widgets/text/text_block.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,7 @@ class EditableTextBlock extends StatelessWidget {
MediaQuery.devicePixelRatioOf(context),
cursorCont,
);
var nodeTextDirection = getDirectionOfNode(line);
// verify if the direction from nodeTextDirection is the default direction
// and watch if the system language is a RTL language and avoid putting
// to the edge of the left side any checkbox or list point/number if is a
// RTL language
if (nodeTextDirection == TextDirection.ltr &&
textDirection == TextDirection.rtl) {
nodeTextDirection = TextDirection.rtl;
}
final nodeTextDirection = getDirectionOfNode(line, textDirection);
children.add(
Directionality(
textDirection: nodeTextDirection,
Expand Down

0 comments on commit 8dc294c

Please sign in to comment.