Skip to content

Clamp editor intrinsic height in small viewports - #950

Open
Michael Greene (mgreenegit) wants to merge 1 commit into
microsoft:mainfrom
mgreenegit:fix/editor-height-small-viewports
Open

Clamp editor intrinsic height in small viewports#950
Michael Greene (mgreenegit) wants to merge 1 commit into
microsoft:mainfrom
mgreenegit:fix/editor-height-small-viewports

Conversation

@mgreenegit

@mgreenegit Michael Greene (mgreenegit) commented Sep 11, 2026

Copy link
Copy Markdown
Member

Problem

The editor calculates its text area's requested height by subtracting the rows reserved for surrounding UI from the viewport height:

Search state Reserved rows
Hidden or disabled 2
Search 4
Replace 5

When the viewport is shorter than that reservation, the result is negative. For example, a three-row viewport with Replace active requests a text-area height of 3 - 5 = -2.

The intrinsic-size setter stores that value without clamping it. The layout engine then uses intrinsic heights to calculate parent sizes and position subsequent children. The negative result therefore enters layout arithmetic; it is not merely discarded before layout.

Change

Keep the existing reserved-row calculation, but clamp the resulting text-area height to zero:

text height = max(viewport height - reserved rows, 0)

This preserves the previous result whenever enough space is available. When the reserved rows consume all available height, the text area requests zero rows rather than a negative number.

The calculation is extracted into a private function so its boundary behavior can be tested without initializing a terminal or constructing editor state. The production drawing path calls that same function.

The clamp is local to the code that converts the editor's viewport and UI reservation into a requested text height. It does not change the layout engine's semantics for other callers or redesign the existing row reservations.

Value and scope

This removes a negative-size input from the existing editor layout and gives insufficient-height boundaries an explicit, regression-tested result.

  • One source file; no dependencies, public API, settings, commands, or platform-specific code.
  • Existing height calculations remain unchanged whenever the reserved rows fit.
  • No claim that all controls become visible or usable in an arbitrarily short terminal. The guarantee is limited to a nonnegative requested text-area height.

Validation

The regression covers hidden, disabled, search, and replace states, with:

  • Heights 0 through 8, below, at, and above each reservation.
  • Decreasing and increasing sequences of those heights.
  • Ordinary heights of 24 and 80, and the maximum supported coordinate height.
  • Assertions for both nonnegative output and the unchanged result when sufficient space exists.

During preparation, the regression failed before the clamp: height 1 with 2 reserved rows produced -1. The proposed branch preserves that tested patch.

Local verification of this branch on Windows with Rust 1.97.1:

cargo test --offline --locked --package edit --bin edit
# 3 passed; 0 failed; 0 ignored

cargo clippy --offline --locked --package edit --bin edit --tests -- --no-deps --deny warnings
# passed

These are calculation-level tests, not an end-to-end terminal-resize test or evidence of a reproduced crash. Cross-platform validation is left to upstream CI; local results are not a claim that CI has passed.

When the viewport is shorter than the rows reserved for editor chrome or search, draw_editor currently supplies a negative intrinsic height. Clamp the available text height to zero, preserving existing heights when space is sufficient. Keep the calculation private and cover hidden/disabled/search/replace modes at zero, boundary, normal, and maximum supported heights, including shrinking and growing sequences.

Provenance: extract the nonnegative height calculation used in console-exploration-0 at 1d21f16b14998d643ff79e4ce36bb519e3d1fd7b (also retained in combined-exploration-0 at a0f14a4). This is an independently useful console prerequisite, not the embedded console feature. No providers, AI, process launch, dependencies, settings, public API, or keyboard behavior are added.

Validation: the focused regression failed before the clamp (height 1, reserved 2 yielded -1). cargo test --locked --package edit --bin edit passes all 3 tests afterward on Windows with msrustup ms-prod rustc 1.97.1. Candidate structural gate accepted. Review/rollback boundary: this one file; revert this commit independently.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
(cherry picked from commit af11d6bd14bbc30b786173772b6d2d648150c518)
@mgreenegit
Michael Greene (mgreenegit) marked this pull request as ready for review September 11, 2026 21:55
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