(root: Element, start: Position, end: Position)
| 641 | } |
| 642 | |
| 643 | function createDOMRange(root: Element, start: Position, end: Position): Range { |
| 644 | let range = document.createRange(); |
| 645 | let child = root.childNodes[start.index]; |
| 646 | if (!child) { |
| 647 | range.setStart(root, Math.min(root.childNodes.length, start.index)); |
| 648 | } else if (child.nodeType === Node.ELEMENT_NODE) { |
| 649 | // Place the cursor in one of the zero width space nodes. |
| 650 | range.setStart(child, start.offset > 0 ? 2 : 0); |
| 651 | } else { |
| 652 | // Place the cursor in the text node. |
| 653 | range.setStart(child, start.offset); |
| 654 | } |
| 655 | child = root.childNodes[end.index]; |
| 656 | if (!child) { |
| 657 | range.setEnd(root, Math.min(root.childNodes.length, end.index)); |
| 658 | } else if (child.nodeType === Node.ELEMENT_NODE) { |
| 659 | range.setEnd(child, end.offset > 0 ? 2 : 0); |
| 660 | } else { |
| 661 | range.setEnd(child, end.offset); |
| 662 | } |
| 663 | return range; |
| 664 | } |
| 665 | |
| 666 | function useSelectionChange(ref: React.RefObject<Element | null>, handler: () => void) { |
| 667 | useEvent(useRef(document), 'selectionchange', () => { |
no outgoing calls
no test coverage detected