MCPcopy Create free account
hub / github.com/caseywebdev/react-list / restoreSelection

Function restoreSelection

docs/index.js:5666–5756  ·  view source on GitHub ↗
(priorSelectionInformation, containerInfo)

Source from the content-addressed store, hash-verified

5664 );
5665}
5666function restoreSelection(priorSelectionInformation, containerInfo) {
5667 var curFocusedElem = getActiveElementDeep(containerInfo);
5668 containerInfo = priorSelectionInformation.focusedElem;
5669 var priorSelectionRange = priorSelectionInformation.selectionRange;
5670 if (
5671 curFocusedElem !== containerInfo &&
5672 containerInfo &&
5673 containerInfo.ownerDocument &&
5674 containsNode(containerInfo.ownerDocument.documentElement, containerInfo)
5675 ) {
5676 if (null !== priorSelectionRange && hasSelectionCapabilities(containerInfo))
5677 if (
5678 ((priorSelectionInformation = priorSelectionRange.start),
5679 (curFocusedElem = priorSelectionRange.end),
5680 void 0 === curFocusedElem &&
5681 (curFocusedElem = priorSelectionInformation),
5682 "selectionStart" in containerInfo)
5683 )
5684 (containerInfo.selectionStart = priorSelectionInformation),
5685 (containerInfo.selectionEnd = Math.min(
5686 curFocusedElem,
5687 containerInfo.value.length
5688 ));
5689 else if (
5690 ((curFocusedElem =
5691 ((priorSelectionInformation =
5692 containerInfo.ownerDocument || document) &&
5693 priorSelectionInformation.defaultView) ||
5694 window),
5695 curFocusedElem.getSelection)
5696 ) {
5697 curFocusedElem = curFocusedElem.getSelection();
5698 var length = containerInfo.textContent.length,
5699 start = Math.min(priorSelectionRange.start, length);
5700 priorSelectionRange =
5701 void 0 === priorSelectionRange.end
5702 ? start
5703 : Math.min(priorSelectionRange.end, length);
5704 !curFocusedElem.extend &&
5705 start > priorSelectionRange &&
5706 ((length = priorSelectionRange),
5707 (priorSelectionRange = start),
5708 (start = length));
5709 length = getNodeForCharacterOffset(containerInfo, start);
5710 var endMarker = getNodeForCharacterOffset(
5711 containerInfo,
5712 priorSelectionRange
5713 );
5714 length &&
5715 endMarker &&
5716 (1 !== curFocusedElem.rangeCount ||
5717 curFocusedElem.anchorNode !== length.node ||
5718 curFocusedElem.anchorOffset !== length.offset ||
5719 curFocusedElem.focusNode !== endMarker.node ||
5720 curFocusedElem.focusOffset !== endMarker.offset) &&
5721 ((priorSelectionInformation =
5722 priorSelectionInformation.createRange()),
5723 priorSelectionInformation.setStart(length.node, length.offset),

Callers 1

commitRootImplFunction · 0.85

Calls 4

getActiveElementDeepFunction · 0.85
containsNodeFunction · 0.85
hasSelectionCapabilitiesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…