Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Mutable entity can be broke into multiple lines. May cause bugs. #903

Open
cadina opened this issue Dec 29, 2016 · 2 comments
Open

Mutable entity can be broke into multiple lines. May cause bugs. #903

cadina opened this issue Dec 29, 2016 · 2 comments

Comments

@cadina
Copy link

cadina commented Dec 29, 2016

Reproducing steps:

  1. Open examples/draft-0-9-1/link/link.html
  2. Enter text: Hello World
  3. Add link on text Hello World
  4. Insert line-breaks after word Hello

Now the words Hello and World are separated and other elements can be inserted between them. But both of the words are still pointing to the same link entity, which means data manipulations on one part will affect the other.

I think it's an unexpected behavior of entities. May cause some strange bugs after breaking a mutable entity.

@sophiebits
Copy link
Contributor

Good catch. We could do something like cloning the entity data in cases like this, but it's not clear at this point what that would look like.

@thibaudcolas
Copy link
Contributor

If anyone wants to solve this in their project, I've made a function that will clone entities when there are multiple ranges pointing at the same one: https://github.com/thibaudcolas/draftjs-filters/blob/d24e5fe6a30e3051429122ac2963f5e2e9d5ef59/src/lib/filters/entities.js#L7-L70.

This was initially meant to be executed on copy-paste (by default, copy-pasting an entity would create a new range pointing to the same entity, #504), but can also be executed when pressing enter or similar so it covers this scenario as well.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants