(
/** @type {string} */ data,
/** @type {number} */ start,
/** @type {number} */ end
)
| 4814 | }; |
| 4815 | |
| 4816 | const insertCharacters = ( |
| 4817 | /** @type {string} */ data, |
| 4818 | /** @type {number} */ start, |
| 4819 | /** @type {number} */ end |
| 4820 | ) => { |
| 4821 | const place = appropriatePlace(); |
| 4822 | if (place.parent.type === NodeType.Document) return; // never insert text into document |
| 4823 | // Inlined text insert: when the run merges into the adjacent text sibling |
| 4824 | // (common with inline formatting) only the string is appended — no |
| 4825 | // throwaway text node is allocated. Mirrors `insertAtPlace`/`appendTo`, |
| 4826 | // including that the before-node merge does not bump `end`. |
| 4827 | const arr = childrenOf(place.parent); |
| 4828 | if (place.beforeNode) { |
| 4829 | const idx = arr.indexOf(place.beforeNode); |
| 4830 | const prev = idx > 0 ? arr[idx - 1] : undefined; |
| 4831 | if (prev && prev.type === NodeType.Text) { |
| 4832 | prev.data += data; |
| 4833 | return; |
| 4834 | } |
| 4835 | arr.splice(idx, 0, { type: NodeType.Text, data, start, end }); |
| 4836 | } else { |
| 4837 | const last = arr[arr.length - 1]; |
| 4838 | if (last && last.type === NodeType.Text) { |
| 4839 | last.data += data; |
| 4840 | last.end = end; |
| 4841 | return; |
| 4842 | } |
| 4843 | arr.push({ type: NodeType.Text, data, start, end }); |
| 4844 | } |
| 4845 | }; |
| 4846 | |
| 4847 | /** |
| 4848 | * @param {string} data comment data |
no test coverage detected