Skip to content

Forward ResizeEvent to ViewModel input observable#219

Merged
Aaronontheweb merged 1 commit into
devfrom
fix/forward-resize-event
May 23, 2026
Merged

Forward ResizeEvent to ViewModel input observable#219
Aaronontheweb merged 1 commit into
devfrom
fix/forward-resize-event

Conversation

@Aaronontheweb

Copy link
Copy Markdown
Owner

Bug

TerminaApplication.ProcessEvent's case ResizeEvent short-circuits with return; after calling _diffingTerminal?.ForceFullRefresh(), so the event never reaches _inputSubject.OnNext(inputEvent) at the bottom of the method. Pages and ViewModels that subscribe via ViewModel.Input.OfType<IInputEvent, ResizeEvent>() never receive resize notifications, even though the framework processes the event internally.

This blocks any consumer that wants to recompute width- or height-sensitive layout on terminal resize — e.g., shortening status-bar text on narrow terminals, swapping wide/narrow key-hint variants, or rebuilding a width-aware truncation.

// src/Termina/TerminaApplication.cs (before)
case ResizeEvent resize:
    TerminaTrace.Render.Debug(this, "ResizeEvent: {0}x{1}", resize.Width, resize.Height);
    _diffingTerminal?.ForceFullRefresh();
    return;   // ← swallows the event; never publishes to consumers

Compare with MouseScrollEvent a few cases below at line 647: when it isn't consumed by a focused scrollable, it breaks to the fall-through _inputSubject.OnNext(inputEvent). The framework already established the right pattern; ResizeEvent predates it.

Fix

One-line change: return;break;. Internal ForceFullRefresh behavior is unchanged; the event additionally surfaces on the public Input observable so consumers can subscribe.

case ResizeEvent resize:
    TerminaTrace.Render.Debug(this, "ResizeEvent: {0}x{1}", resize.Width, resize.Height);
    _diffingTerminal?.ForceFullRefresh();
    break;   // ← falls through to _inputSubject.OnNext(inputEvent)

Test

Adds tests/Termina.Tests/Input/ResizeEventRoutingTests.cs that mirrors the existing PasteToastRoutingTests reflection pattern — dispatch a ResizeEvent through ProcessEvent and assert it surfaces on the ViewModel's Input observable. Two cases:

  • ProcessEvent_ForwardsResizeEvent_ToViewModelInputObservable — single resize is observed with correct width/height.
  • ProcessEvent_StillRefreshesDiffingTerminal_OnResize — two back-to-back distinct resizes each surface independently (locks in that the loop doesn't dedup/swallow on repeated dispatch).

Downstream

Discovered while implementing terminal-size-aware approval prompt rendering in netclaw (#1132). The netclaw fix subscribes ViewModel.Input.OfType<ResizeEvent>() to recompute width-sensitive layout, but the subscription was silently never firing in production — the bug masquerades as "resize handling works in tests but not in real terminals."

Test plan

`TerminaApplication.ProcessEvent`'s `case ResizeEvent` short-circuited
with `return;` after calling `_diffingTerminal?.ForceFullRefresh()`, so
the event never reached `_inputSubject.OnNext(inputEvent)`. Pages and
ViewModels subscribing via `ViewModel.Input.OfType<ResizeEvent>()` never
received resize notifications, which blocks any width- or height-aware
layout recomputation on terminal resize.

Replace `return;` with `break;` so the event falls through to the
`_inputSubject.OnNext` publish at the bottom of the method, matching
the pattern `MouseScrollEvent` already uses a few cases below
(handled-by-focused-scrollable returns, otherwise falls through).
Internal `ForceFullRefresh` behavior is unchanged.

Adds `ResizeEventRoutingTests` that dispatch a `ResizeEvent` through
`ProcessEvent` (via reflection, mirroring `PasteToastRoutingTests`) and
assert it surfaces on the ViewModel's `Input` observable. Two cases
cover single-resize forwarding and back-to-back distinct resizes.

@Aaronontheweb Aaronontheweb left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Aaronontheweb Aaronontheweb merged commit d785bce into dev May 23, 2026
11 checks passed
@Aaronontheweb Aaronontheweb deleted the fix/forward-resize-event branch May 23, 2026 18:38
Aaronontheweb added a commit that referenced this pull request May 23, 2026
- Update version to 0.10.0
- Add release notes for v0.10.0 with PRs #220, #219, #215, #217
- Update PackageReleaseNotes in Directory.Build.props
- Update RELEASE_NOTES.md with full release notes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant