Skip to content

[CTX-1386] fix(ui): start new panels at row zero - #2313

Merged
Xuepoo merged 1 commit into
mainfrom
ctx-1386/fix-new-panel-stray-row
Oct 20, 2026
Merged

Xuepoo merged 1 commit into
mainfrom
ctx-1386/fix-new-panel-stray-row

Conversation

@Xuepoo

@Xuepoo Xuepoo commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Priority: P2 | Area: ui | Labels: fix,P2,area:ui | Milestone: 0.0.25 | RFC: - | Task: CTX-1386

Closes #2145

Root cause

TerminalApp::commit_new_leaf sized a fresh pane's shell from layout_allocations() — the raw slot after gaps, before the border/content inset. The very first present then shrank the pane grid and PTY to the decorated content frame immediately after the shell started. That post-spawn SIGWINCH makes the shell repaint its prompt; a prompt hook that draws its repaint on a fresh line leaves a stray blank first row above the prompt. Running clear happened to repaint without that extra row, which is why it looked like a one-off grid offset.

The path affected only the keymap split/new-panel actions (NewSplit, NewPanel, including the empty-base materialization). workspace_new and session restore already spawn from the present frame.

Evidence

  • Default headless runtime: a new NewSplit pane was spawned at 40x24 while its presented content frame was 37x22; the first tick() then resized both grid and PTY, delivering the spurious SIGWINCH.
  • A real fish + starship pane reproduced the same shape: grid 80x24 vs frame 77x22 before the first present.
  • workspace_new already spawned at 77x22 with no follow-up resize.

Change

commit_new_leaf now resolves the size from present_frames() first and falls back to layout_allocations() only for a degenerate container. The shell is born at its final content size, and the first geometry sync is a no-op.

The move-panel path already sizes the pane from the target's decorated content frame; a resize there only happens when the target geometry genuinely differs and it preserves the top content rows.

Regression

new_leaf_spawns_at_its_presented_content_frame runs both NewSplit and NewPanel, asserts the PTY and grid are born at the presented content frame, and asserts the first present does not resize either.

Before the fix it failed with:

left: Some((40, 24))
right: Some((37, 22))

After the fix it passes.

Verification

  • just fmt-check
  • cargo clippy -p bitty-terminal --all-targets --locked -- -D warnings
  • cargo nextest run -p bitty-terminal --locked: 1247 passed, 1 skipped
  • cargo nextest run -p bitty-terminal --locked -E 'test(chrome_keys)': 130 passed
  • cargo check --target x86_64-pc-windows-gnu --workspace --all-targets --locked
  • just check: green (workspace nextest 7572 passed / 3 skipped, doctests, platform harnesses, supply chain, packaging, actionlint, markdownlint)

Scope note

A prompt framework that intentionally emits a leading newline before every prompt (for example starship add_newline = true, its default) is a prompt choice, not a bitty grid offset; this change does not suppress prompt bytes the shell intentionally writes.

Summary by CodeRabbit

  • Bug Fixes
    • New split panes and panels now open at the dimensions of the displayed content area when available.
    • Added fallback sizing to ensure panes launch correctly when displayed dimensions are unavailable.
    • Prevented unnecessary resizing immediately after pane creation.

@Xuepoo Xuepoo added this to the 0.0.25 milestone Oct 20, 2026
@Xuepoo Xuepoo added fix Bug fix area:ui Area: UI / layout P2 Priority: medium labels Oct 20, 2026
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 10 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fdc07959-884a-401b-8c3d-a1f4f4932586
📥 Commits

Reviewing files that changed from the base of the PR and between c7c8d7a and 92a1ece.

📒 Files selected for processing: 1
  • crates/bitty-terminal/src/chrome_keys.rs

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8ee95f80-dc27-4385-813b-82d248c62cae
📥 Commits

Reviewing files that changed from the base of the PR and between 6bab90f and c72b501.

📒 Files selected for processing: 1
  • crates/bitty-terminal/src/chrome_keys.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

New panes now use presented content-frame dimensions for initial shell and grid sizing when available. Layout allocation and (80, 24) are fallback sizes. A PTY-backed regression test covers both split and panel creation.

Changes: Pane spawn sizing

Layer / File(s) Summary
Initialize panes from presented dimensions
crates/bitty-terminal/src/chrome_keys.rs
commit_new_leaf uses the presented frame dimensions for shell and grid sizing, then falls back to layout allocation and (80, 24). Test setup accepts an injected SpawnSpec and selects an interactive shell by platform. A PTY-backed test checks NewSplit and NewPanel without an initial resize.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to c72b5

No actionable issue remains on the supplied evidence; the pane-sizing change is ready for normal merge checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the UI fix for new panels starting at row zero. This matches the pull request’s main behavior change, which prevents a blank row by spawning new panes at their presented c…
Linked Issues check Passed Issue [#2145] requires fresh and moved panels to start at the prompt's first row without a resize-induced blank row. commit_new_leaf now uses present_frames() before raw layout allocations, so new…
Out of Scope Changes check Passed The changes are limited to new-pane sizing in commit_new_leaf, a regression test, and test spawn configuration for platform shells. These changes directly support issue [#2145]. No unrelated product…
Full details: Title check

Explanation

The title clearly identifies the UI fix for new panels starting at row zero. This matches the pull request’s main behavior change, which prevents a blank row by spawning new panes at their presented content-frame size.

Full details: Linked Issues check

Explanation

Issue [#2145] requires fresh and moved panels to start at the prompt's first row without a resize-induced blank row. commit_new_leaf now uses present_frames() before raw layout allocations, so new shells use the presented content size. The regression test covers NewSplit and NewPanel, and verifies both PTY and grid sizes before and after the first tick. The existing move-panel path already uses the target content frame, as documented in the PR evidence.

Full details: Out of Scope Changes check

Explanation

The changes are limited to new-pane sizing in commit_new_leaf, a regression test, and test spawn configuration for platform shells. These changes directly support issue [#2145]. No unrelated production behavior is changed.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Xuepoo Xuepoo modified the milestones: 0.0.25, 0.0.24 Oct 20, 2026
@Xuepoo
Xuepoo force-pushed the ctx-1386/fix-new-panel-stray-row branch from 2822e72 to c72b501 Compare October 20, 2026 09:38
@Xuepoo

Xuepoo commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Review verdict: APPROVE

Reviewed head c72b501b (includes 2822e728 plus the Windows test portability fix).

Root cause and fix

  • commit_new_leaf now resolves the fresh pane from present_frames() (the decorated content frame it is actually presented in), with layout_allocations() only as a degenerate-container fallback. No clear, no post-render trim, no PTY write.
  • set_layout already reflows the leaf to that frame, so the first present's geometry sync is a no-op.
  • New panel, split, and the empty-base materialization all share this funnel. The move path is unchanged: it already re-syncs the moved session to the target present_frames() via sync_pane_geometry, and State::resize copies top rows, so no row-zero offset is introduced. Existing panels, cursor, and selection paths are untouched.

Regression and mutation

  • new_leaf_spawns_at_its_presented_content_frame covers both NewSplit and NewPanel, asserting the PTY and grid start at the presented frame and the first tick() does not resize either.
  • Mutation: reverting the present_frames() lookup to layout_allocations() fails exactly as claimed: left: Some((40, 24)) right: Some((37, 22)). Restored; worktree clean.

Windows portability

  • The test is not #[cfg(unix)]-gated and runs on Windows. platform_spawn_spec() selects COMSPEC/cmd.exe on Windows and /bin/sh on Unix.
  • On Unix, a missing /bin/sh makes the spawn fail and the size assertion fail; it does not skip the check or mask the row-zero regression.

Gates (head c72b501b)

  • cargo fmt --all -- --check: pass
  • cargo clippy -p bitty-terminal --all-targets --locked -- -D warnings: pass
  • cargo nextest run -p bitty-terminal -p bitty-ui -p bitty-term-state --locked with CARGO_TARGET_DIR=.targets/review-2313b: 2041 passed, 1 skipped
  • Review target dir removed.
  • Head CI is green (Quality gates, Windows, macOS, Linux, MSRV, CodeQL, Supply chain).

No code blockers. Merge note: the PR is MERGEABLE but currently BEHIND main by two commits, so the branch needs an update before the merge gate is clean.

@Xuepoo
Xuepoo force-pushed the ctx-1386/fix-new-panel-stray-row branch from c72b501 to c7c8d7a Compare October 20, 2026 10:39
Size a fresh pane's shell to the decorated content frame it is presented
in instead of the raw slot allocation. The first present used to shrink
grid and PTY immediately after spawn, delivering a SIGWINCH that repaints
the prompt and can leave a blank first row above it.

Regression: new_leaf_spawns_at_its_presented_content_frame (fails before:
40x24 vs 37x22; passes after).

Refs #2145.
@Xuepoo
Xuepoo force-pushed the ctx-1386/fix-new-panel-stray-row branch from c7c8d7a to 92a1ece Compare October 20, 2026 11:44
@Xuepoo
Xuepoo merged commit 60c3d54 into main Oct 20, 2026
18 checks passed
@Xuepoo
Xuepoo deleted the ctx-1386/fix-new-panel-stray-row branch October 20, 2026 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ui Area: UI / layout fix Bug fix P2 Priority: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] new panel shows a stray blank first row (needs clear to remove)

1 participant