- Package: clayterm
- Version: v0.6.0 (reproduced on
main @ d75fb4b)
- Runtime: Deno 2.x
- OS: platform-independent (WASM); reproduced on macOS
Describe the bug
We track a single active clip rect instead of a stack, so nesting one clip inside another corrupts clipping for later siblings. When an inner clip closes, clipping switches off entirely rather than restoring the parent rect, so anything drawn after leaks past the outer bounds. With an outer clip of height 4 (rows 0-3) holding an inner clip plus a tall sibling, the sibling's ZZZZ/WWWW render at rows 4-5 (both should be blank). Horizontally it leaks the same way: an outer width-4 clip with a narrower inner one renders a later sibling as all 8 columns (SSSSSSSS) instead of SSSS. Single-level clipping already works.
To Reproduce
The vertical case leaks ZZZZ/WWWW onto rows 4-5; the horizontal case renders the sibling as SSSSSSSS instead of SSSS .
Expected behavior
Clip regions should form a stack. Entering a clip pushes intersect(parent active rect, child box); leaving pops it, restoring the parent rect for subsequent siblings, so an inner clip never disables the outer one. The grid should be:
Additional Information
Failing test case on nm/repro/nested-clip (test · diff). Clay emits balanced SCISSOR_START/SCISSOR_END pairs in DFS order, so the render-command walk just needs to maintain a stack. The fix likely lives in src/clayterm.c:621 (SCISSOR_START overwrites the active rect; should push intersect(parent, child)) and src/clayterm.c:628 (SCISSOR_END sets clipping = 0; should pop and keep clipping on while the stack is non-empty). The scalar clip state at src/clayterm.c:48-50 needs a small fixed-depth rect stack (~16 is ample); the setcell test at src/clayterm.c:70-86 stays correct once sourced from the stack top. C-only, no wire/JS/public-API change; depth-1 nesting reduces to today's single-rect behavior.
main@ d75fb4b)Describe the bug
We track a single active clip rect instead of a stack, so nesting one clip inside another corrupts clipping for later siblings. When an inner clip closes, clipping switches off entirely rather than restoring the parent rect, so anything drawn after leaks past the outer bounds. With an outer clip of height 4 (rows 0-3) holding an inner clip plus a tall sibling, the sibling's
ZZZZ/WWWWrender at rows 4-5 (both should be blank). Horizontally it leaks the same way: an outer width-4 clip with a narrower inner one renders a later sibling as all 8 columns (SSSSSSSS) instead ofSSSS. Single-level clipping already works.To Reproduce
The vertical case leaks
ZZZZ/WWWWonto rows 4-5; the horizontal case renders the sibling asSSSSSSSSinstead ofSSSS.Expected behavior
Clip regions should form a stack. Entering a clip pushes
intersect(parent active rect, child box); leaving pops it, restoring the parent rect for subsequent siblings, so an inner clip never disables the outer one. The grid should be:Additional Information
Failing test case on
nm/repro/nested-clip(test · diff). Clay emits balancedSCISSOR_START/SCISSOR_ENDpairs in DFS order, so the render-command walk just needs to maintain a stack. The fix likely lives insrc/clayterm.c:621(SCISSOR_STARToverwrites the active rect; should pushintersect(parent, child)) andsrc/clayterm.c:628(SCISSOR_ENDsetsclipping = 0; should pop and keep clipping on while the stack is non-empty). The scalar clip state atsrc/clayterm.c:48-50needs a small fixed-depth rect stack (~16 is ample); thesetcelltest atsrc/clayterm.c:70-86stays correct once sourced from the stack top. C-only, no wire/JS/public-API change; depth-1 nesting reduces to today's single-rect behavior.