Queue highlight rendering so startup work stays serialized without starving input/render timers.
(run: () => T)
| 594 | |
| 595 | /** Queue highlight rendering so startup work stays serialized without starving input/render timers. */ |
| 596 | function queueHighlightedWork<T>(run: () => T) { |
| 597 | const queued = queuedHighlightWork.then( |
| 598 | () => |
| 599 | new Promise<T>((resolve, reject) => { |
| 600 | // Highlighting is CPU-heavy background work. Scheduling each serialized job as a timer, |
| 601 | // rather than a microtask, yields back to OpenTUI input and frame timers between files. |
| 602 | setTimeout(() => { |
| 603 | try { |
| 604 | resolve(run()); |
| 605 | } catch (error) { |
| 606 | reject(error); |
| 607 | } |
| 608 | }, 0); |
| 609 | }), |
| 610 | ); |
| 611 | |
| 612 | queuedHighlightWork = queued.then( |
| 613 | () => undefined, |
| 614 | () => undefined, |
| 615 | ); |
| 616 | |
| 617 | return queued; |
| 618 | } |
| 619 | |
| 620 | /** Normalize source text the same way expanded-row slicing does before highlighting. */ |
| 621 | function normalizeSourceText(text: string) { |
no test coverage detected