Skip to content

Conversation

mohamadlounnas
Copy link

@mohamadlounnas mohamadlounnas commented Mar 22, 2025

before:

Screenshot 2025-03-22 at 6 50 00 PM

after the fix:

Screenshot 2025-03-22 at 6 49 47 PM

@mohamadlounnas mohamadlounnas changed the title [SuperEditor] - Fix selection highlight alignment for RTL languages and update dependencies in pubspec.lock [SuperEditor] - Fix selection highlight alignment for RTL languages Mar 22, 2025
@matthew-carroll
Copy link
Contributor

@mohamadlounnas I see that you added a Positioned widget, but I have no idea why that fixed anything.

Can you please describe the root of the problem, and why a Positioned widget solves it?

@mohamadlounnas
Copy link
Author

@mohamadlounnas I see that you added a Positioned widget, but I have no idea why that fixed anything.

Can you please describe the root of the problem, and why a Positioned widget solves it?

Hey @matthew-carroll,

The issue occurs when selecting RTL text ,the highlight is flipped because RTL text itself is mirrored, causing the highlight to start from -100%:
Screenshot 2025-03-22 at 6 50 00 PM

You can try it yourself. I fixed it by forcing the highlight layer to stay within the positive area of the stack, as shown in the image:
Screenshot 2025-03-22 at 6 49 47 PM

@matthew-carroll
Copy link
Contributor

@angelosilvestre can you check on the root cause for this? I'm skeptical that the correct solution is to add a Positioned widget, but I'm still not sure what the root cause of this really is.

@mohamadlounnas
Copy link
Author

@angelosilvestre can you check on the root cause for this? I'm skeptical that the correct solution is to add a Positioned widget, but I'm still not sure what the root cause of this really is.

The main issue is that CustomPainter starts drawing from left to right only, and currently has no inherent size (0,0). In RTL mode, this causes it to stick to the top right and begin drawing from there towards the right.

To fix this, we can use Positioned (as i did) to enforce constraints on its children or wrap the CustomPainter with a SizedBox set to width: double.infinity to ensure it receives constraints

Screenshot 2025-04-02 at 5 37 08 AM Screenshot 2025-04-02 at 5 17 03 AM

@mohamadlounnas
Copy link
Author

Since the issue originates from super_text_layout (and it may also be used in other projects), I think it's better to fix it within that package.

For now, wrapping it with SizedBox.shrink seems to resolve the problem.
new pull request: #2638

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