Reproducable with the rich example:
This doesn't seem intended behavior?
It doesn't happen in the FB Notes editor, though.
Repros in the Notes composer for me, but I think this behavior isn't really wrong.
What's happening here is not that the first block is being deleted, but that the text from the second block is being pulled upward into the first block. The first block keeps its block type. This makes it appear that the first block was removed, and the second block was changed to be unstyled.
We could instead remove the first block completely, and move the cursor into the second block.
What do other editors do in this scenario?
Just tested on a Mac.
Google Docs, Microsoft Word and Apple Pages all keep the H1 styles.
Just generally speaking, it feels like there are edge cases/unique handling for at least:
Fair enough. It seems like that's consistent enough to change within RichUtils. I'm open to accepting a PR for this.
In fact, in the Firefox, it doesn't delete the styling. But I can reproduce the steps in Chrome.
@hellendag When you say RichUtils, you mean you'ld change it in RichUtils.onDelete, and assume the user that wants this behavior has handleKeyCommand hooked up to his component?
The alternative is to change the behavior in removeRangeFromContentState where the actual logic of joining the blocks is, making it default behavior.
@hellendag _bump_ There's some comments spread around some issues and PRs on Draft block join/split behavior (this issue on joining, there's a mention about splitting on https://github.com/facebook/draft-js/pull/216#issuecomment-197979832, #188 on splitting blocks). Could you confirm which behavior you'd accept changes for where? I'm going to need these behaviors soon, so I'd like to figure out where it makes sense to create PRs for, and where to use external custom behavior.
To recap, the behaviors I'm thinking of (which seem to be pretty standard AFAICT):
onDelete? Does this ensure that all the cases are handled properly? (as raised in https://github.com/facebook/draft-js/pull/216#issuecomment-197979832 )Seems like RichUtils is the right place for this. If there are patterns that are common for Google Docs, MS Word, and others, I think it's fair to follow those conventions.
(copying comment from #266)
My impression is that this should be done at a lower level than RichUtils, like in DraftModifier.removeRange. In particular, here is where we choose to keep the preceding block's attributes:
It seems like the best way to fix this is to thread through a removalDirection boolean down to that function from all of its callers and choose whether to use startBlock or endBlock appropriately given that direction.
Note that RichTextEditorUtil does not currently handle this logic (DraftModifier and/or removeRangeFromContentState do), so I don't think it makes sense to try to work around that low-level "broken" behavior with a change in a higher-level module.
I think this is related: when I select the entire text of a block (including the trailing return) and press delete, it keeps the block type and pulls the text up from the following block. I expect it to cleanly delete the block.
Probably also related: in the media example, there's no way of having just an image, there's always an unstyled empty block in front. If you hit 'delete' in an editor like Google Docs, it will remove the empty block and move the image up.
Most helpful comment
(copying comment from #266)
My impression is that this should be done at a lower level than RichUtils, like in DraftModifier.removeRange. In particular, here is where we choose to keep the preceding block's attributes:
https://github.com/facebook/draft-js/blob/bb6175cb5038acee8abec3c0a696e4eef5b30e01/src/model/transaction/removeRangeFromContentState.js#L53
It seems like the best way to fix this is to thread through a
removalDirectionboolean down to that function from all of its callers and choose whether to usestartBlockorendBlockappropriately given that direction.Note that RichTextEditorUtil does not currently handle this logic (DraftModifier and/or removeRangeFromContentState do), so I don't think it makes sense to try to work around that low-level "broken" behavior with a change in a higher-level module.