[PR #813] fix(core): update hitGrid dimensions on all resizes, not just growth #1582

Open
opened 2026-03-14 09:44:38 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/anomalyco/opentui/pull/813
Author: @sbbae0318
Created: 3/14/2026
Status: 🔄 Open

Base: mainHead: fix/hitgrid-resize-dimensions


📝 Commits (2)

  • f9a851c fix(core): update hitGrid dimensions on all resizes, not just growth
  • ffe0492 test(core): add regression tests for hitGrid resize dimension tracking

📊 Changes

2 files changed (+143 additions, -2 deletions)

View changed files

packages/core/src/tests/scrollbox-hitgrid-resize.test.ts (+136 -0)
📝 packages/core/src/zig/renderer.zig (+7 -2)

📄 Description

Fixes #812

Summary

hitGridWidth/hitGridHeight were only updated inside the if (newHitGridSize > currentHitGridSize) block, so shrinking the terminal (e.g. making it narrower but taller) left stale dimensions in place. checkHit then returned 0 for any coordinate past the old bounds, breaking mouse event dispatch for the bottom portion of the screen.

Changes

  • packages/core/src/zig/renderer.zig: Move hitGridWidth/hitGridHeight assignment out of the reallocation guard so they track the actual terminal size on every resize.
  • packages/core/src/tests/scrollbox-hitgrid-resize.test.ts: Add regression tests covering hit grid behavior after terminal shrink and multi-cycle resizes.

The backing buffer was allocated for the larger dimensions, so using a smaller width*height against it is safe -- every index y * hitGridWidth + x stays within the allocated capacity.

Testing

Three regression tests added:

  • Hit grid returns correct targets at all Y coordinates after shrink
  • Mouse scroll events reach ScrollBox after shrink
  • Hit grid survives multiple grow/shrink resize cycles

All 3926 existing tests continue to pass.

Reproduction

  1. Start an opentui app with a scrollbox at 160x50
  2. Resize to 60x100 (total area 6000 < 8000, so the grid doesn't reallocate)
  3. Mouse scroll below row 50 -- no hit target, scroll is dropped
  4. Start fresh at 60x100 -- works fine (grid was initialized at 60x100)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/anomalyco/opentui/pull/813 **Author:** [@sbbae0318](https://github.com/sbbae0318) **Created:** 3/14/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/hitgrid-resize-dimensions` --- ### 📝 Commits (2) - [`f9a851c`](https://github.com/anomalyco/opentui/commit/f9a851c91bb14393d2c9ed110e688ecdfe9bf6e6) fix(core): update hitGrid dimensions on all resizes, not just growth - [`ffe0492`](https://github.com/anomalyco/opentui/commit/ffe04926f65841474674ed989ec233e40ee1ae96) test(core): add regression tests for hitGrid resize dimension tracking ### 📊 Changes **2 files changed** (+143 additions, -2 deletions) <details> <summary>View changed files</summary> ➕ `packages/core/src/tests/scrollbox-hitgrid-resize.test.ts` (+136 -0) 📝 `packages/core/src/zig/renderer.zig` (+7 -2) </details> ### 📄 Description Fixes #812 ## Summary `hitGridWidth`/`hitGridHeight` were only updated inside the `if (newHitGridSize > currentHitGridSize)` block, so shrinking the terminal (e.g. making it narrower but taller) left stale dimensions in place. `checkHit` then returned 0 for any coordinate past the old bounds, breaking mouse event dispatch for the bottom portion of the screen. ## Changes - `packages/core/src/zig/renderer.zig`: Move `hitGridWidth`/`hitGridHeight` assignment out of the reallocation guard so they track the actual terminal size on every resize. - `packages/core/src/tests/scrollbox-hitgrid-resize.test.ts`: Add regression tests covering hit grid behavior after terminal shrink and multi-cycle resizes. The backing buffer was allocated for the larger dimensions, so using a smaller width*height against it is safe -- every index `y * hitGridWidth + x` stays within the allocated capacity. ## Testing Three regression tests added: - Hit grid returns correct targets at all Y coordinates after shrink - Mouse scroll events reach ScrollBox after shrink - Hit grid survives multiple grow/shrink resize cycles All 3926 existing tests continue to pass. ## Reproduction 1. Start an opentui app with a scrollbox at 160x50 2. Resize to 60x100 (total area 6000 < 8000, so the grid doesn't reallocate) 3. Mouse scroll below row 50 -- no hit target, scroll is dropped 4. Start fresh at 60x100 -- works fine (grid was initialized at 60x100) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/opentui#1582
No description provided.