lexical icon indicating copy to clipboard operation
lexical copied to clipboard

Bug: Left to right vs Right to left selection styles not available

Open enbanil opened this issue 1 year ago • 2 comments

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

  1. Select a text and apply text color.
  2. Select text from right to left - Range selection has styles available.
  3. Select left to right - Range selection has no styles though text has styles applied.

Tab-1729021879743.webm

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.

enbanil avatar Oct 15 '24 19:10 enbanil

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.

etrepum avatar Oct 16 '24 00:10 etrepum

Is there any solution to this problem?

enbanil avatar Jan 24 '25 03:01 enbanil