(root: Element, pos: Position)
| 843 | } |
| 844 | |
| 845 | function getDOMPosition(root: Element, pos: Position): [Node, number] { |
| 846 | let index = Math.max(0, Math.min(root.childNodes.length, pos.index)); |
| 847 | let child = root.childNodes[index]; |
| 848 | if (!child) { |
| 849 | return [root, index]; |
| 850 | } else if (child.nodeType === Node.ELEMENT_NODE) { |
| 851 | // Place the cursor outside the token wrapper element. |
| 852 | // This is necessary for composition events. |
| 853 | if (pos.offset > 0) { |
| 854 | return [root, index + 1]; |
| 855 | } else { |
| 856 | return [root, index]; |
| 857 | } |
| 858 | } else { |
| 859 | let offset = Math.max(0, Math.min(child.textContent?.length ?? 0, pos.offset)); |
| 860 | return [child, offset]; |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | function isSamePosition(a: Position, b: Position): boolean { |
| 865 | return a.index === b.index && a.offset === b.offset; |
no outgoing calls
no test coverage detected