Issue
The progressive rendering system applied semantic coloring for Markdown labels (e.g., ‘Tools:’) prematurely, before the colon character appeared in the rendered output. This resulted in inconsistent visual effects where:
- Characters in labels were incorrectly colored turquoise (semantic label style) before the colon was visible.
- The semantic meaning of ‘text before colons’ was visually enforced before the colon was rendered.
- The expected behavior required text to remain green (normal body text) until the colon appeared, followed by retroactive turquoise coloring for the entire label.
This issue was particularly problematic in progressive text reveal animations, where text appears character-by-character but semantic rules were evaluated during tokenization rather than at render time.
Culprit
The problem arose from a mismatch between tokenization-time and render-time coloring processes:
- Premature coloring: The system assigned semantic coloring (e.g., turquoise for labels) during tokenization, before any frames were rendered.
- Static color baking: Colors were pre-calculated for all characters during layout pre-calculation and stored in a static dictionary.
- Stateless rendering: The parallel rendering architecture processed frames independently without shared state about previously rendered characters.
- Missing frame context: Rendering workers lacked information about which characters (e.g., colons) would appear in subsequent frames, leading to incorrect early application of semantic colors.
Solution
To resolve this issue, a render-time color override system was implemented, consisting of two key components:
Colon Visibility Tracking
The system now tracks which lines contain visible colons in each frame. This allows the rendering process to dynamically adjust the coloring of characters based on the visibility of the colon in the same line.
Dynamic Color Override
At render time, characters marked for semantic coloring (e.g., turquoise) are checked to determine if the colon has appeared in their line. If the colon is not yet visible, the character reverts to normal body text color (green) until the colon appears. This ensures semantic coloring is applied only after the colon is rendered.
Key Benefits
- Performance: Minimal performance impact with efficient set lookups during rendering.
- Compatibility: Maintains compatibility with the existing tokenization and layout systems without requiring major refactoring.
- Precision: Uses Y-coordinate-based line identification to handle wrapped lines, scrolling, and multiple colons.
- Edge Cases: Correctly handles complex scenarios such as multiple colons and dynamic content.
This solution ensures that semantic coloring rules are applied correctly during the progressive rendering process, maintaining visual consistency with the expected behavior of the system.