Bug: Left to right vs Right to left selection styles not available
The left-to-right text selection range comes without styles, on the other hand, the right-to-left selection of the text comes up with the styles.
Lexical version: 0.18.0
Steps To Reproduce
- Select a text and apply text color.
- Select text from right to left - Range selection has styles available.
- Select left to right - Range selection has no styles though text has styles applied.
Link to code example:
https://playground.lexical.dev/
The current behavior
Range selection has no styles though text has styles applied.
The expected behavior
Range selection has styles available on both LTR and RTL selection.
Impact of fix
Strange behavior upon change of selection direction and it is not consistent.
The reason this happens is because there's initially an ambiguity for which style to use because there are two possible nodes when the selection is at a node boundary and lexical chooses a left-biased approach. You can see this by moving the selection to the boundary between two text nodes and look at which key/offset the selection starts at, it's always the leftmost one. The bug is that when you extend the selection to the right it does move the anchor to the right node but it doesn't change the style to match accordingly.
Is there any solution to this problem?