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

Advantages relative to getBoundingClientRect? #43

Open
malcolmredheron opened this issue Sep 27, 2017 · 4 comments
Open

Advantages relative to getBoundingClientRect? #43

malcolmredheron opened this issue Sep 27, 2017 · 4 comments

Comments

@malcolmredheron
Copy link

This project sounds great but I can't tell why this is better than window.getSelection().getRangeAt(0).getBoundingClientRect()? Are there cases where that fails but this library works?

If so, I think that it would be great to cover this in the readme.

@tnhu
Copy link

tnhu commented Nov 12, 2017

@malcolmredheron How do you use window.getSelection().getRangeAt(0).getBoundingClientRect()? I could never get it to work. It always gives me { bottom: 0, height: 0, left: 0, right:0, top: 0, width: 0, x: 0, y: 0 }

@ghost
Copy link

ghost commented Nov 13, 2017

.getBoundingClientRect() doesn't appear to work for a selection inside a textarea unless I'm mistaken. I see the same behaviour as @tnhu when trying to swap out getCaretCoordinates(el, el.selectionStart) for window.getSelection().getRangeAt(0).getBoundingClientRect()

It does seem to work for selections in normal divs etc.

@ghost
Copy link

ghost commented Nov 13, 2017

https://stackoverflow.com/questions/46516425/why-range-getboundingclientrect-returns-0-for-range-inside-textarea

Seems like if you were using a contentEditiable div instead, it would work.

@malcolmredheron
Copy link
Author

Ah, ok. I'm using a contenteditable and didn't realize that my approach was specific to that.

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

No branches or pull requests

2 participants