(root: Element, start: Position, end: Position)
| 689 | } |
| 690 | |
| 691 | function createDOMRange(root: Element, start: Position, end: Position): Range { |
| 692 | let range = document.createRange(); |
| 693 | let startChild = root.childNodes[start.index]; |
| 694 | if (!startChild) { |
| 695 | range.setStart(root, Math.min(root.childNodes.length, start.index)); |
| 696 | } else if (startChild.nodeType === Node.ELEMENT_NODE) { |
| 697 | // Place the cursor outside the token wrapper element. |
| 698 | if (start.offset > 0) { |
| 699 | range.setStartAfter(startChild); |
| 700 | } else { |
| 701 | range.setStartBefore(startChild); |
| 702 | } |
| 703 | } else { |
| 704 | range.setStart(startChild, start.offset); |
| 705 | } |
| 706 | |
| 707 | let endChild = root.childNodes[end.index]; |
| 708 | if (!endChild) { |
| 709 | range.setEnd(root, Math.min(root.childNodes.length, end.index)); |
| 710 | } else if (endChild.nodeType === Node.ELEMENT_NODE) { |
| 711 | if (end.offset > 0) { |
| 712 | range.setEndAfter(endChild); |
| 713 | } else { |
| 714 | range.setEndBefore(endChild); |
| 715 | } |
| 716 | } else { |
| 717 | range.setEnd(endChild, end.offset); |
| 718 | } |
| 719 | return range; |
| 720 | } |
| 721 | |
| 722 | function isSamePosition(a: Position, b: Position): boolean { |
| 723 | return a.index === b.index && a.offset === b.offset; |
no outgoing calls
no test coverage detected