* @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)
| 6773 | * nodes and place them back in, resulting in focus being lost. |
| 6774 | */ |
| 6775 | function restoreSelection(priorSelectionInformation) { |
| 6776 | var curFocusedElem = getActiveElement(); |
| 6777 | var priorFocusedElem = priorSelectionInformation.focusedElem; |
| 6778 | var priorSelectionRange = priorSelectionInformation.selectionRange; |
| 6779 | if (curFocusedElem !== priorFocusedElem && isInDocument(priorFocusedElem)) { |
| 6780 | if (hasSelectionCapabilities(priorFocusedElem)) { |
| 6781 | setSelection(priorFocusedElem, priorSelectionRange); |
| 6782 | } |
| 6783 | |
| 6784 | // Focusing a node can change the scroll position, which is undesirable |
| 6785 | var ancestors = []; |
| 6786 | var ancestor = priorFocusedElem; |
| 6787 | while (ancestor = ancestor.parentNode) { |
| 6788 | if (ancestor.nodeType === ELEMENT_NODE) { |
| 6789 | ancestors.push({ |
| 6790 | element: ancestor, |
| 6791 | left: ancestor.scrollLeft, |
| 6792 | top: ancestor.scrollTop |
| 6793 | }); |
| 6794 | } |
| 6795 | } |
| 6796 | |
| 6797 | priorFocusedElem.focus(); |
| 6798 | |
| 6799 | for (var i = 0; i < ancestors.length; i++) { |
| 6800 | var info = ancestors[i]; |
| 6801 | info.element.scrollLeft = info.left; |
| 6802 | info.element.scrollTop = info.top; |
| 6803 | } |
| 6804 | } |
| 6805 | } |
| 6806 | |
| 6807 | /** |
| 6808 | * @getSelection: Gets the selection bounds of a focused textarea, input or |
no test coverage detected