()
| 343 | }; |
| 344 | |
| 345 | const flushChanges = () => { |
| 346 | state.queue.push(...state.observer.takeRecords()); |
| 347 | const position = getPosition(element); |
| 348 | if (state.queue.length) { |
| 349 | disconnect(); |
| 350 | const content = toString(element); |
| 351 | state.position = position; |
| 352 | let mutation: MutationRecord | void; |
| 353 | let i = 0; |
| 354 | while ((mutation = state.queue.pop())) { |
| 355 | if (mutation.oldValue !== null) |
| 356 | mutation.target.textContent = mutation.oldValue; |
| 357 | for (i = mutation.removedNodes.length - 1; i >= 0; i--) |
| 358 | mutation.target.insertBefore( |
| 359 | mutation.removedNodes[i], |
| 360 | mutation.nextSibling |
| 361 | ); |
| 362 | for (i = mutation.addedNodes.length - 1; i >= 0; i--) |
| 363 | if (mutation.addedNodes[i].parentNode) |
| 364 | mutation.target.removeChild(mutation.addedNodes[i]); |
| 365 | } |
| 366 | |
| 367 | state.onChange(content, position); |
| 368 | } |
| 369 | }; |
| 370 | |
| 371 | const onKeyDown = (event: HTMLElementEventMap['keydown']) => { |
| 372 | if (event.defaultPrevented || event.target !== element) { |
no test coverage detected
searching dependent graphs…