draft-js icon indicating copy to clipboard operation
draft-js copied to clipboard

Inline styles not recognised if the selection starts on a blank line

Open DouglasLivingstone opened this issue 8 years ago • 4 comments

togglebold

To reproduce:

  1. Press return inside the text box
  2. Type on the second line
  3. Select all the text
  4. Press to toggle bold on (note that it doesn't go blue)
  5. Press to toggle bold off

Step 5 doesn't work, the text stays bold. Seems to be due to the selection starting on a blank line, the current style is detected as already non-bold.

This is possibly related to #412

DouglasLivingstone avatar May 24 '16 11:05 DouglasLivingstone

Interesting bug, thanks for reporting.

sophiebits avatar May 24 '16 18:05 sophiebits

Nice catch.

It seems like empty blocks should still carry a style, and not have to be based purely on surrounding content. Right now we would look upward at the previous block and use the style of its last character. I think it's fair to say that this doesn't always make sense, including in this case, where looking upward leads to the start of the document and the assumption that there is no style.

This is slightly different from #412, though related in that the editor looks upward for the appropriate style rather than using override information.

For a fix, a couple ideas:

  • Support a style override property on ContentBlock, perhaps in its metadata object.
  • Look downward instead of upward in cases like these.

hellendag avatar Jun 02 '16 19:06 hellendag

Here is one more case of this bug Kapture 2020-06-27 at 14 16 24

newsiberian avatar Jun 27 '20 07:06 newsiberian

Met the same issue during my integration. I've tried doing some workaround, but it seems using a trick by mutating the state like callingtoggleInlineStyle still doesn't work for me.

willnew avatar Jul 18 '22 02:07 willnew