Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neighboring embeds collapse together #312

Closed
thomsbg opened this issue Mar 20, 2015 · 0 comments
Closed

Neighboring embeds collapse together #312

thomsbg opened this issue Mar 20, 2015 · 0 comments

Comments

@thomsbg
Copy link
Contributor

thomsbg commented Mar 20, 2015

Quill collapses adjacent Leaf objects with identical formats into a single Leaf. This is desirable for normal inline formats, but causes some trouble with embed formats. For example, running these commands on the quilljs.com homepage throws a javascript error:

quill.setContents({ ops: [] })
quill.insertEmbed(0, 'image', '/images/quill-photo.jpg')

// throws an error related to shifting the cursor,
// expected two <img> elements, but there is only one.
quill.insertEmbed(0, 'image', '/images/quill-photo.jpg')

console.log(JSON.stringify(quill.getContents())
// "{"ops":[{"attributes":{"image":"/images/quill-photo.jpg"},"insert":"!!\n"}]}"

I'm not sure of the best solution for this, but it seems like adjacent embeds shouldn't collapse in order to reflect the desired markup: <div><img><img></div>. Also, the newline probably shouldn't have the embed format either. i.e. the call to getContents() after these operations should look like:

{ ops: [
  { insert: 1, attributes: { image: '/images/quill-photo.jpg' } },
  { insert: 1, attributes: { image: '/images/quill-photo.jpg' } },
  { insert: '\n' }
] }
thomsbg added a commit to voxmedia/quill that referenced this issue Mar 24, 2015
Avoiding the optimization of inserting text into an existing node with
identical formats which fixes quilljs#312.

Without this optimization, insertText() will always split the existing
html at the offset and create a new node just for the inserted text.
To achieve similar behavior as before, Line#optimize() is called instead of
thomsbg added a commit to voxmedia/quill that referenced this issue Mar 24, 2015
Avoiding the optimization of inserting text into an existing node with
identical formats which fixes quilljs#312.

Without this optimization, insertText() will always split the existing
html at the offset and create a new node just for the inserted text.
To achieve similar behavior as before, Line#optimize() is called instead of
thomsbg added a commit to voxmedia/quill that referenced this issue Mar 24, 2015
Avoiding the optimization of inserting text into an existing node with
identical formats fixes quilljs#312.

Without this optimization, insertText() will always split the existing
html at the offset and create a new node just for the inserted text.
To achieve similar behavior as before, Line#optimize() is called instead of
thomsbg added a commit to voxmedia/quill that referenced this issue Mar 24, 2015
Avoiding the optimization of inserting text into an existing node with
identical formats fixes quilljs#312.

Without this optimization, insertText() will always split the existing
html at the offset and create a new node just for the inserted text.
To achieve similar behavior as before, Line#optimize() is called instead of
Line#rebuild().
@jhchen jhchen closed this as completed in 813a3f3 Mar 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant