Skip to content

Fix image selection #58

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

Merged
merged 1 commit into from
May 20, 2020
Merged

Fix image selection #58

merged 1 commit into from
May 20, 2020

Conversation

alecgibson
Copy link
Collaborator

@alecgibson alecgibson commented May 20, 2020

Fixes #57

This change fixes a bug that can be reproduced by:

  1. Run the development app
  2. Paste an image into the editor
  3. Select all
  4. The "remote" cursor does not highlight the image, and the console
    errors

This is because when using Range.setStart and Range.setEnd, the
offset argument is treated differently for non-text nodes.

This change updates our range definitions to check if the leaf in
question is a text node or not. If it is a text node, then we use the
offset as before. However, if it isn't a text node (eg an img), then
we simply set the selection before/after the node using
Range.setStartBefore and Range.setEndAfter.

This change fixes a bug that can be reproduced by:

 1. Run the development app
 2. Paste an image into the editor
 3. Select all
 4. The "remote" cursor does not highlight the image, and the console
    errors

This is because when using `Range.setStart` and `Range.setEnd`, the
`offset` argument is treated differently for non-text nodes.

This change updates our range definitions to check if the leaf in
question is a text node or not. If it is a text node, then we use the
offset as before. However, if it isn't a text node (eg an `img`), then
we simply set the selection before/after the node using
`Range.setStartBefore` and `Range.setEndAfter`.
Copy link

@ricardoferrolho ricardoferrolho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 Nice one!

@alecgibson alecgibson merged commit c21b6fb into master May 20, 2020
@alecgibson alecgibson deleted the image-fix branch May 20, 2020 09:24
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 this pull request may close these issues.

IndexSizeError after inserting image and then selecting everything in the editor
2 participants