* @restoreSelection: If any selection information was potentially lost, * restore it. This is useful when performing operations that could remove dom * nodes and place them back in, resulting in focus being lost.
(priorSelectionInformation)
| 6557 | * nodes and place them back in, resulting in focus being lost. |
| 6558 | */ |
| 6559 | function restoreSelection(priorSelectionInformation) { |
| 6560 | var curFocusedElem = getActiveElement(); |
| 6561 | var priorFocusedElem = priorSelectionInformation.focusedElem; |
| 6562 | var priorSelectionRange = priorSelectionInformation.selectionRange; |
| 6563 | if (curFocusedElem !== priorFocusedElem && isInDocument(priorFocusedElem)) { |
| 6564 | if (hasSelectionCapabilities(priorFocusedElem)) { |
| 6565 | setSelection(priorFocusedElem, priorSelectionRange); |
| 6566 | } |
| 6567 | |
| 6568 | // Focusing a node can change the scroll position, which is undesirable |
| 6569 | var ancestors = []; |
| 6570 | var ancestor = priorFocusedElem; |
| 6571 | while (ancestor = ancestor.parentNode) { |
| 6572 | if (ancestor.nodeType === ELEMENT_NODE) { |
| 6573 | ancestors.push({ |
| 6574 | element: ancestor, |
| 6575 | left: ancestor.scrollLeft, |
| 6576 | top: ancestor.scrollTop |
| 6577 | }); |
| 6578 | } |
| 6579 | } |
| 6580 | |
| 6581 | priorFocusedElem.focus(); |
| 6582 | |
| 6583 | for (var i = 0; i < ancestors.length; i++) { |
| 6584 | var info = ancestors[i]; |
| 6585 | info.element.scrollLeft = info.left; |
| 6586 | info.element.scrollTop = info.top; |
| 6587 | } |
| 6588 | } |
| 6589 | } |
| 6590 | |
| 6591 | /** |
| 6592 | * @getSelection: Gets the selection bounds of a focused textarea, input or |
no test coverage detected