lexical: Bug: `$getSelectionStyleValueForProperty(selection, 'font-size')` not updating correctly

When using $getSelectionStyleValueForProperty(selection, 'font-size'), it does not seem to update if user changes font size on some text which has previously modified its font size. The font-family property also exhibits the same behavior.

Lexical version: 0.10.0

Steps To Reproduce

This can be reproduced in the https://playground.lexical.dev/:

  1. Open lexical playground
  2. Change font size for some text
  3. Click away from the text
  4. Highlight that same text again, and change the font size

I’ve also created a sandbox, see FontSizePlugin: https://codesandbox.io/s/dazzling-visvesvaraya-8pjcv5

Repro in sandbox by:

  1. Type some text and highlight it
  2. Change font size to 24px
  3. Deselect text and reselect
  4. Change font size to 48px

See that the text font size does change, but the getSelectionStyleValueForProperty result still says ‘24px’.

The current behavior

Toolbar does not update, but text font size does change. getSelectionStyleValueForProperty seems to still return the original value.

The expected behavior

getSelectionStyleValueForProperty will return the new font size, so that the toolbar can update to new font size.

This only happens for text that has font size changed, the initial change from no font-size to some value does seem to update correctly.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 15 (4 by maintainers)

Most upvoted comments

@GAURAV1-ui any progress here?

@acywatson can this get unassigned/reassigned if not?

thanks @Piliuta for taking your time and answering me 😃 I’ve installed the latest version from 3 days ago (0.12.4) and it works perfectly!

Hi @Piliuta,

Do you mind explaining why this PR actually fix the bug? 😃 What’s the difference between background-color and font-family and how it is related to the selection being collapsed or not.

Thanks, Roey

They are both “style” properties, so they are the same from the selection perspective. There is a bug in the core functionality that does not update the property value when the selection is not collapsed. The PR fixes the $getSelectionStyleValueForProperty method so it does not return value from the style property of the selection but calculates the value from the selection state.

This seems to be a larger problem with the selection that does not reflect the correct inline style value. I have other steps to reproduce the issue. Testes on the playground https://playground.lexical.dev/

https://github.com/facebook/lexical/assets/1575198/93d94950-47c7-400a-bbe7-e6803adf9f8c

@acywatson It’s been 4+ months since it was assigned to @GAURAV1-ui but no updates. Is it possible for somebody from the lexical core team to work on it?