(root: Element, pos: Position)
| 760 | } |
| 761 | |
| 762 | function getDOMPosition(root: Element, pos: Position): [Node, number] { |
| 763 | let index = Math.max(0, Math.min(root.childNodes.length, pos.index)); |
| 764 | let child = root.childNodes[index]; |
| 765 | if (!child) { |
| 766 | return [root, index]; |
| 767 | } else if (child.nodeType === Node.ELEMENT_NODE) { |
| 768 | // Place the cursor outside the token wrapper element. |
| 769 | // This is necessary for composition events. |
| 770 | if (pos.offset > 0) { |
| 771 | return [root, index + 1]; |
| 772 | } else { |
| 773 | return [root, index]; |
| 774 | } |
| 775 | } else { |
| 776 | let offset = Math.max(0, Math.min(child.textContent?.length ?? 0, pos.offset)); |
| 777 | return [child, offset]; |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | function isSamePosition(a: Position, b: Position): boolean { |
| 782 | return a.index === b.index && a.offset === b.offset; |
no outgoing calls
no test coverage detected