-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fixed a bug related to draft losing its selection #1571
Conversation
|
Amazing! We would love to have this! |
juliankrispel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for this @pferdone! Just left one comment about adding a test to protect against regressions. 👍
| // after the range is detached. | ||
| var range = selection.getRangeAt(0); | ||
| range.setEnd(node, offset); | ||
| selection.addRange(range.cloneRange()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mind adding a failing test for the above and then adding your test which fixes it? That'd prevent a regression
| // | ||
| // Added rangeCount check | ||
| // https://stackoverflow.com/questions/22935320/uncaught-indexsizeerror-failed-to-execute-getrangeat-on-selection-0-is-not | ||
| if (selection.rangeCount > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've run into this before, legit error! Thanks for the pr! I'll bring it up and hopefully we can merge this in soonish
|
Pleas merge.... |
|
I still experience this with Draft-js v I have a workaround but I had to try and hide it in a larger commit it's so ugly. |
|
Is there any particular reason why this really simple bugfix has not been merged yet after more than 1.5 years? I am experiencing the same problem nearwood described last november and it crashes the entire app in IE11 (can't ignore IE because of client requirements). The only way I could make it work is applying this fix manually and working with a fixed local dependency, which of course is super ugly and cuts the app off from any future updates to draft.js. |
…selection when there is not one (#2271) Summary: **Summary** Various browsers will throw errors if `selection.getRangeAt(0)` is called when there is no range. To fix this, a check was added to make sure a range exists. This change was originally suggested [here](#1571) a few years ago. I opted for opening a new PR and adding tests here since that PR seemed stale. Selection and Range did not work in the test environment, so I had to stub them. I only added functionality for what was needed in the tests I added, but more can be added in the future very easily. Pull Request resolved: #2271 Differential Revision: D18807105 Pulled By: mrkev fbshipit-source-id: 0e3b833b8a3267b9a5f17b262b6a0442b6ae5e3d
|
ping? |
|
hello ? I also have the same error |
…selection when there is not one (facebookarchive#2271) Summary: **Summary** Various browsers will throw errors if `selection.getRangeAt(0)` is called when there is no range. To fix this, a check was added to make sure a range exists. This change was originally suggested [here](facebookarchive#1571) a few years ago. I opted for opening a new PR and adding tests here since that PR seemed stale. Selection and Range did not work in the test environment, so I had to stub them. I only added functionality for what was needed in the tests I added, but more can be added in the future very easily. Pull Request resolved: facebookarchive#2271 Differential Revision: D18807105 Pulled By: mrkev fbshipit-source-id: 0e3b833b8a3267b9a5f17b262b6a0442b6ae5e3d
|
This was already merged in #2271 |
…selection when there is not one (facebookarchive#2271) Summary: **Summary** Various browsers will throw errors if `selection.getRangeAt(0)` is called when there is no range. To fix this, a check was added to make sure a range exists. This change was originally suggested [here](facebookarchive#1571) a few years ago. I opted for opening a new PR and adding tests here since that PR seemed stale. Selection and Range did not work in the test environment, so I had to stub them. I only added functionality for what was needed in the tests I added, but more can be added in the future very easily. Pull Request resolved: facebookarchive#2271 Differential Revision: D18807105 Pulled By: mrkev fbshipit-source-id: 0e3b833b8a3267b9a5f17b262b6a0442b6ae5e3d
Summary
Sometimes rangeCount <= 0 and Draft tries to access an index that's out of range. See stackoverflow for a simplified example. Chrome throws the following exception:
Fix
I added a rangeCount check.