* @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)
| 6615 | * nodes and place them back in, resulting in focus being lost. |
| 6616 | */ |
| 6617 | function restoreSelection(priorSelectionInformation) { |
| 6618 | var curFocusedElem = getActiveElement(); |
| 6619 | var priorFocusedElem = priorSelectionInformation.focusedElem; |
| 6620 | var priorSelectionRange = priorSelectionInformation.selectionRange; |
| 6621 | if (curFocusedElem !== priorFocusedElem && isInDocument(priorFocusedElem)) { |
| 6622 | if (hasSelectionCapabilities(priorFocusedElem)) { |
| 6623 | setSelection(priorFocusedElem, priorSelectionRange); |
| 6624 | } |
| 6625 | |
| 6626 | // Focusing a node can change the scroll position, which is undesirable |
| 6627 | var ancestors = []; |
| 6628 | var ancestor = priorFocusedElem; |
| 6629 | while (ancestor = ancestor.parentNode) { |
| 6630 | if (ancestor.nodeType === ELEMENT_NODE) { |
| 6631 | ancestors.push({ |
| 6632 | element: ancestor, |
| 6633 | left: ancestor.scrollLeft, |
| 6634 | top: ancestor.scrollTop |
| 6635 | }); |
| 6636 | } |
| 6637 | } |
| 6638 | |
| 6639 | priorFocusedElem.focus(); |
| 6640 | |
| 6641 | for (var i = 0; i < ancestors.length; i++) { |
| 6642 | var info = ancestors[i]; |
| 6643 | info.element.scrollLeft = info.left; |
| 6644 | info.element.scrollTop = info.top; |
| 6645 | } |
| 6646 | } |
| 6647 | } |
| 6648 | |
| 6649 | /** |
| 6650 | * @getSelection: Gets the selection bounds of a focused textarea, input or |
no test coverage detected