Deepest last text node under `root` (matches insertAdjacentText tail).
(root: Node)
| 178 | |
| 179 | /** Deepest last text node under `root` (matches insertAdjacentText tail). */ |
| 180 | function findLastTextNode(root: Node): Text | null { |
| 181 | if (root.nodeType === Node.TEXT_NODE) { |
| 182 | const text = root as Text; |
| 183 | return text.data.length > 0 ? text : null; |
| 184 | } |
| 185 | |
| 186 | for (let i = root.childNodes.length - 1; i >= 0; i--) { |
| 187 | const found = findLastTextNode(root.childNodes[i]!); |
| 188 | if (found) { |
| 189 | return found; |
| 190 | } |
| 191 | } |
| 192 | return null; |
| 193 | } |
| 194 | |
| 195 | function collapseRangeAtTextEnd(range: Range, text: Text): void { |
| 196 | range.setStart(text, text.data.length); |
no outgoing calls
no test coverage detected