This repository has been archived by the owner on Feb 6, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use pasted block type if pasting to empty unstyled block
Summary: DraftJS's paste handling is a little bit weird right now. Suppose you have some arbitrary HTML that looks like this ``` <div> <h1>Some h1 content</h1> <span>Some other content</span> </div> ``` or a DraftJS editor with an H1 block and an unstyled block with the same contents. In either case, if you select both blocks of this content and paste into an empty editor, you get two blocks: one H1 and one unstyled. But if you select *only the first block* and paste into an empty editor, you get a single unstyled block. When you are inserting multiple blocks, `insertFragmentIntoContentState` checks whether to use the type of the target block or the pasted block based on whether the target block is empty: ``` return block.merge({ text: headText + appendToHead.getText(), characterList: headCharacters.concat(appendToHead.getCharacterList()), type: headText ? block.getType() : appendToHead.getType(), data: appendToHead.getData(), }); ``` https://our.intern.facebook.com/intern/diffusion/WWW/browse/master/html/shared/draft-js/model/transaction/insertFragmentIntoContentState.js?commit=1001924671&lines=105 But when inserting a single block, this logic is not used. This diff adds a similar check in `updateExistingBlock`, which handles the single block case. The difference is that the single block case **only** uses the inserted text's block type if the target block is **unstyled**. I did this because I thought it would be weird if you tried to paste text into a bulleted list or a block quote and it removed the styling. Reviewed By: mrkev Differential Revision: D20774564 fbshipit-source-id: c1490e17e5ecacea7891f9c7a5880f7eab8831e7
- Loading branch information
This applies the new block type in case of NONempty block, but it seems that the you wanted to apply it in case of empty block (based on commit message), which also makes more sense ...