(ref: React.RefObject<Element | null>, handler: () => void)
| 664 | } |
| 665 | |
| 666 | function useSelectionChange(ref: React.RefObject<Element | null>, handler: () => void) { |
| 667 | useEvent(useRef(document), 'selectionchange', () => { |
| 668 | if (isProgrammaticSelectionChange) { |
| 669 | isProgrammaticSelectionChange = false; |
| 670 | return; |
| 671 | } |
| 672 | |
| 673 | let selection = window.getSelection(); |
| 674 | if (!selection || selection.rangeCount === 0 || !ref.current) { |
| 675 | return; |
| 676 | } |
| 677 | |
| 678 | let range = selection.getRangeAt(0); |
| 679 | if (range.intersectsNode(ref.current)) { |
| 680 | handler(); |
| 681 | } |
| 682 | }); |
| 683 | } |
| 684 | |
| 685 | function isCollapsed(pos1: Position, pos2: Position) { |
| 686 | return pos1.index === pos2.index && pos1.offset === pos2.offset; |
no test coverage detected