-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Modifier.replaceWithFragment() loses block type if fragment size === 1 #1511
Comments
Consider this: suppose I have a block whose type is If we use the fragment's block type in this case then the result of the paste is that the block's text is changed to That, I think, would be an unpleasant experience. |
Thanks for the explanation @colinjeanne - that makes sense as to why it is the way it is then! I'm afraid I'm not familiar enough with DraftJS' workings to even begin to suggest something that would work in both instances. By that, I mean I am currently attempting to copy and paste an image. I parse the HTML in |
I recognize that the current draft behavior is desirable in the majority of circumstances; however, it would be nice to be able to manually override the current behavior of I have a custom block insertion util based on draft's However, it would be really nice not to wind up with a bunch of extra empty blocks getting inserted into documents. I'm wondering if it would be possible to pass a flag to |
Hi @colinjeanne, do you have any explanation for what scenario is the following code (mentioned ealier by @tomkelsey) in there?
Based on your explanation, it should either keep the block data of the existing block, or at least merge the original and new block data. Is that a bug or is there a logical explanation why type is not applied from inserted fragment but data is? |
@kenticomartinh, I don't have a good explanation for that. It seems to me that it should use the target block's data for consistency rather than the pasted block's data. In our own editor where we use block data we end up detecting this case and setting the data explicitly. The data field is, in particular, difficult to deal with because it is just a generic data store. Draft has no idea what is in it or what the semantics are so merging doesn't seem like a sound option. Even if it merges it would still need to decide whether the target or the pasted block takes precedence when they have different values for the same key. |
It also seems to me there should be a way to replace the type. Are there any known workarounds for this? |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Modifier.replaceWithFragment()
loses block type iffragment size === 1
What is the expected behavior?
Modifier.replaceWithFragment()
persists block typeOther
I don't know if there's a wider reason for this that I haven't understood yet but
https://github.com/facebook/draft-js/blob/c1150a729080d04014551d1c78292cb05da7cf1b/src/model/transaction/insertFragmentIntoContentState.js#L61
I believe there should be an extra line after
data: pastedBlock.getData()
withtype: pastedBlock.getType()
as this would seemingly resolve the issue?The text was updated successfully, but these errors were encountered: