HubSpot / draft-convert

Extensibly serialize & deserialize Draft.js ContentState with HTML.
Apache License 2.0
483 stars 94 forks source link

Ensure correct block keys in selectionState after conversion from HTML #118

Closed rayd closed 6 years ago

rayd commented 6 years ago

When converting HTML to a ContentBlock, we start with an empty block to get a starting ContentState object. However, the starting block is overwritten when we set the 'blockMap' based on the blocks created from the HTML. At this point, the 'selectionBefore' and 'selectionAfter' properties of the ContentBlock still reference the original block's key which is no longer valid. This change ensures that we correctly set the keys in 'selectionBefore' and 'selectionAfter' to match the first block of the ContentState. There's also a test added to check this case.

rayd commented 6 years ago

What's your preferred way for me to resolve the merge conflict? Merge master into my branch, or just rebase on top of the most recent master?

benbriggs commented 6 years ago

ahh my bad i should have waited to merge the prettier stuff. i'd prefer merging master into this branch if that's ok - i think the only conflict will be the imports line being split up

rayd commented 6 years ago

No problem -- I'll do that!

rayd commented 6 years ago

Okay, I think this should be good to go!

benbriggs commented 6 years ago

thanks @rayd!