mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Fix ReactDOMSelection for IE 11
IE 11 no longer supports the legacy document.selection API. Their implementation of window.getSelection() doesn't support the extend() method, which we were relying on. If the selection is RTL and selection extend is missing, then just flip the selection.
This commit is contained in:
committed by
Paul O’Shannessy
parent
10ccd9f103
commit
18bf0b80bc
@@ -137,7 +137,15 @@ function setModernOffsets(node, offsets) {
|
||||
var length = node[getTextContentAccessor()].length;
|
||||
var start = Math.min(offsets.start, length);
|
||||
var end = typeof offsets.end === 'undefined' ?
|
||||
start : Math.min(offsets.end, length);
|
||||
start : Math.min(offsets.end, length);
|
||||
|
||||
// IE 11 uses modern selection, but doesn't support the extend method.
|
||||
// Flip backward selections, so we can set with a single range.
|
||||
if (!selection.extend && start > end) {
|
||||
var temp = end;
|
||||
end = start;
|
||||
start = temp;
|
||||
}
|
||||
|
||||
var startMarker = getNodeForCharacterOffset(node, start);
|
||||
var endMarker = getNodeForCharacterOffset(node, end);
|
||||
@@ -146,8 +154,15 @@ function setModernOffsets(node, offsets) {
|
||||
var range = document.createRange();
|
||||
range.setStart(startMarker.node, startMarker.offset);
|
||||
selection.removeAllRanges();
|
||||
selection.addRange(range);
|
||||
selection.extend(endMarker.node, endMarker.offset);
|
||||
|
||||
if (start > end) {
|
||||
selection.addRange(range);
|
||||
selection.extend(endMarker.node, endMarker.offset);
|
||||
} else {
|
||||
range.setEnd(endMarker.node, endMarker.offset);
|
||||
selection.addRange(range);
|
||||
}
|
||||
|
||||
range.detach();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user