Clamp editor intrinsic height in small viewports - #950
Open
Michael Greene (mgreenegit) wants to merge 1 commit into
Open
Clamp editor intrinsic height in small viewports#950Michael Greene (mgreenegit) wants to merge 1 commit into
Michael Greene (mgreenegit) wants to merge 1 commit into
Conversation
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)
Michael Greene (mgreenegit)
marked this pull request as ready for review
September 11, 2026 21:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The editor calculates its text area's requested height by subtracting the rows reserved for surrounding UI from the viewport height:
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:
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.
Validation
The regression covers hidden, disabled, search, and replace states, with:
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:
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.