Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix IE11 collapsed ranges in ReactDOMSelection
In IE10/11, it is apparently possible to have a Selection or Range object that has the following properties: - `anchorNode` === `focusNode` (Selection) or `startContainer` === `endContainer` (Range) - `anchorOffset` === `focusOffset` (Selection) or `startOffset` === `endOffset` (Range) - `isCollapsed` === `false` (Selection) or `collapsed` === `false` (Range) As defined in http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html, this doesn't really make sense. Since the nodes and offsets are the same, the "collapsed" value should be `true`. Moreover, when calling `selection.toString()` in this case, it appears that the entire text contents of `body` -- including `<script>` tag contents -- are considered within the selection. I thought maybe the selected nodes were missing from the DOM or something, but no, they're there. Sidestep all of this in `ReactDOMSelection` by calculating the `collapsed` property manually and setting the selection length directly to zero if it is actually collapsed. Side note: I think that for selection restoration on contenteditables, we shouldn't try to do this offset calculation. We should just use the structure provided natively (nodes and offsets) since we can restore using that structure as well.
- Loading branch information