draft-js
draft-js copied to clipboard
Inline styles not recognised if the selection starts on a blank line
To reproduce:
- Press return inside the text box
- Type on the second line
- Select all the text
- Press to toggle bold on (note that it doesn't go blue)
- 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
Interesting bug, thanks for reporting.
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.
Here is one more case of this bug
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.