Home / Function/ restoreSelection() — react Function Reference

restoreSelection() — react Function Reference

Architecture documentation for the restoreSelection() function in ReactInputSelection.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  3ffa57aa_7550_476a_22f1_45c9f6827530["restoreSelection()"]
  61ae92ed_59ee_0d03_f7cc_6c7bd8c060f5["ReactInputSelection.js"]
  3ffa57aa_7550_476a_22f1_45c9f6827530 -->|defined in| 61ae92ed_59ee_0d03_f7cc_6c7bd8c060f5
  7330d54b_88aa_2185_79a9_d580cfe8f0ac["getActiveElementDeep()"]
  3ffa57aa_7550_476a_22f1_45c9f6827530 -->|calls| 7330d54b_88aa_2185_79a9_d580cfe8f0ac
  ffb94eb2_a9b7_b0b8_7a69_1e236320f487["isInDocument()"]
  3ffa57aa_7550_476a_22f1_45c9f6827530 -->|calls| ffb94eb2_a9b7_b0b8_7a69_1e236320f487
  a96fa181_7474_eda8_7c38_1e173c424b26["hasSelectionCapabilities()"]
  3ffa57aa_7550_476a_22f1_45c9f6827530 -->|calls| a96fa181_7474_eda8_7c38_1e173c424b26
  8ff85b49_fa19_b78a_6c6a_8dda56ae4f95["setSelection()"]
  3ffa57aa_7550_476a_22f1_45c9f6827530 -->|calls| 8ff85b49_fa19_b78a_6c6a_8dda56ae4f95
  style 3ffa57aa_7550_476a_22f1_45c9f6827530 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-dom-bindings/src/client/ReactInputSelection.js lines 120–155

export function restoreSelection(priorSelectionInformation, containerInfo) {
  const curFocusedElem = getActiveElementDeep(containerInfo);
  const priorFocusedElem = priorSelectionInformation.focusedElem;
  const priorSelectionRange = priorSelectionInformation.selectionRange;
  if (curFocusedElem !== priorFocusedElem && isInDocument(priorFocusedElem)) {
    if (
      priorSelectionRange !== null &&
      hasSelectionCapabilities(priorFocusedElem)
    ) {
      setSelection(priorFocusedElem, priorSelectionRange);
    }

    // Focusing a node can change the scroll position, which is undesirable
    const ancestors = [];
    let ancestor = priorFocusedElem;
    while ((ancestor = ancestor.parentNode)) {
      if (ancestor.nodeType === ELEMENT_NODE) {
        ancestors.push({
          element: ancestor,
          left: ancestor.scrollLeft,
          top: ancestor.scrollTop,
        });
      }
    }

    if (typeof priorFocusedElem.focus === 'function') {
      priorFocusedElem.focus();
    }

    for (let i = 0; i < ancestors.length; i++) {
      const info = ancestors[i];
      info.element.scrollLeft = info.left;
      info.element.scrollTop = info.top;
    }
  }
}

Domain

Subdomains

Frequently Asked Questions

What does restoreSelection() do?
restoreSelection() is a function in the react codebase, defined in packages/react-dom-bindings/src/client/ReactInputSelection.js.
Where is restoreSelection() defined?
restoreSelection() is defined in packages/react-dom-bindings/src/client/ReactInputSelection.js at line 120.
What does restoreSelection() call?
restoreSelection() calls 4 function(s): getActiveElementDeep, hasSelectionCapabilities, isInDocument, setSelection.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free