Skip to content

refactor(terminal): add in-place pane layout geometry apply (unused) - #25671

Merged
Jinwoo-H merged 7 commits into
mainfrom
terminal-topology-b2-2-geometry-apply
Oct 6, 2026
Merged

Jinwoo-H merged 7 commits into
mainfrom
terminal-topology-b2-2-geometry-apply

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​238 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​238
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​143 $\color{#cf222e}{\Huge{\mathbf{−}}}$​15 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​128

ELI5

Later in this refactor the app window will follow main's copy of the terminal layout. When main says "this split is now 60/40" or "this split is now vertical", the window needs to change the panes already on screen without tearing them down (which would lose scrollback and focus). This PR adds that ability. Nothing calls it yet, so nothing changes for users.

What Changed

  • New src/renderer/src/lib/pane-manager/pane-layout-geometry-apply.ts: given a layout, it compares it to the panes on screen split by split. If the panes are not exactly the same set in the same shape (including a split missing its divider), or a pane is currently zoomed to fill the tab, it does nothing (never half-applies). Zoom is skipped because un-zooming restores the pane sizes saved at zoom time and would overwrite anything applied meanwhile. Otherwise it updates split ratios and directions in place, refits the affected panes and restyles dividers. A direction change swaps the divider element, because a divider's drag axis is fixed when it is created. Ratio differences of 0.005 or less are ignored, so a saved layout re-applied moves nothing. The ratio read and that 0.005 limit now live in pane-split-ratio.ts, shared with serializePaneTree (same results as before). It never calls onLayoutChanged, so applying a layout cannot trigger a save.
  • PaneManager.applyLayoutGeometry(layout) exposes it. Two constructor arrow functions were collapsed to single lines to stay under the file's line limit (no behavior change).

Before/after for users: none. There are no production callers; the layout reconciler starts using it in a later PR of this series, together with the protection that stops a host update from undoing an in-progress local drag.

Why

Without in-place apply, the window would have to rebuild panes to follow a layout change from main. Wiring it in now would add cross-client divider syncing (a new feature, not a fix) and could make a divider jump back during a local drag, so it lands inert and is wired up later.

Linked Issue

Maintainer PR. Part of the terminal layout refactor (context: Linear STA-9417, STA-9259).

Visual Proof

N/A: no caller, so no visible change.

Testing

  • pnpm tc, oxlint, oxfmt and check:code-quality:changed pass.

  • 7 new tests on a real PaneManager (happy-dom; xterm's open mocked): a ratio change keeps pane ids, containers and terminal objects with no create/close/layout-changed callbacks; a direction flip keeps the split and swaps the divider; an identical layout makes zero DOM changes (MutationObserver); only a changed nested split updates; a mismatched layout, a zoomed pane, or a split without a divider makes zero changes. Each test was checked by breaking the code; each break fails at least one test.

  • lib/pane-manager and components/terminal-pane suites: all pass except two tests in an untouched file (remote-snapshot-alt-screen-host-chain.test.ts) that time out the same way with this PR's files reverted to main.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Not manually tested in the app: nothing calls the new code.

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

No change to saved state, wire protocols, SSH, mobile or platform behavior.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

PaneManager.applyLayoutGeometry applies a layout's split orientation and
ratios to the mounted pane tree without remounting panes, and never fires
onLayoutChanged. Nothing calls it yet; the live-layout reconciler adopts it
in a later change.
@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 13ca2bae-25d7-4053-ad74-f4f543355130
📥 Commits

Reviewing files that changed from the base of the PR and between f47c892 and 919e14c.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e75895e7-ac2b-4e05-8657-512ab5852083
📥 Commits

Reviewing files that changed from the base of the PR and between ead17a3 and f47c892.

📒 Files selected for processing (5)
  • src/renderer/src/components/terminal-pane/layout-serialization.ts
  • src/renderer/src/lib/pane-manager/pane-layout-geometry-apply.test.ts
  • src/renderer/src/lib/pane-manager/pane-layout-geometry-apply.ts
  • src/renderer/src/lib/pane-manager/pane-manager.ts
  • src/renderer/src/lib/pane-manager/pane-split-ratio.ts

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


📝 Walkthrough

Walkthrough

Adds shared split-ratio reading for layout serialization and a PaneManager method that applies orientation and ratio changes to a mounted pane tree. The geometry update validates the full tree before making DOM changes. Tests cover ratio and orientation updates, nested splits, unchanged layouts, mismatched trees, zoomed trees, and missing dividers.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to f47c8

The new geometry method has no production callers, and the identified ratio concern does not affect supported pane operations. The change is mergeable after normal checks.

Security Architecture Review

Security architecture risk: ⚪ Minimal · up to f47c8

The new operation is not connected to live callers, validates existing pane identities and tree shape before changing geometry, and preserves saved-layout behavior. No material security exposure was identified in this change.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — For a valid invocation, direct geometry effects are bounded to the existing tree of one manager and its affected terminal refits. No current external caller was identified that expands independently attackable session or service scope.

Trust Boundaries and Controls

  • observed — Mounted-tree matching is a compatibility control, not authorization or complete runtime input validation. The existing remote-layout parser validates node types, direction, finite ratios, depth, and node count; the new internal API does not itself call that parser. No new external path bypassing it was identified.

Resilience and Maintainability Implications

  • observed — Zoom-hidden trees are rejected before geometry mutation, preventing writes that collapse would overwrite. Existing safe-fit handling catches terminal fitting failures and releases scroll-state markers; it may defer fitting during a scroll-intent rebuild or flush existing continuations after success.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the main change: adding in-place pane layout geometry application. The “unused” qualifier accurately notes that the new API has no production callers yet.
Description check ✅ Passed The description covers the required sections, explains the change and rationale, describes testing, and marks visual proof as not applicable with a reason. It identifies this as a maintainer PR and pr…
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · 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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • In-place geometry apply (new, unused): pane-layout-geometry-apply.ts validates that the mounted pane tree exactly matches the supplied TerminalPaneLayoutNode — same leaves, same shape, same child order — before touching the DOM. On a mismatch it returns without any writes, so it never half-applies. On a match it updates split directions and flex ratios in place, disposes the old divider and creates a new one on an orientation flip (a divider binds its drag axis at creation), refits the affected panes, and never fires onLayoutChanged.
  • Public API: PaneManager.applyLayoutGeometry(layout) exposes the managed wrapper; the two collapsed constructor arrows in pane-manager.ts are behavior-preserving.
  • Tests: five happy-dom tests on a real PaneManager (ratio-only change preserves pane/container/terminal identity with no create/close/layout-changed callbacks; orientation flip swaps the divider to the new axis; identical layout produces zero DOM mutations via MutationObserver; a nested split changes in isolation; a mismatched tree writes nothing).

I traced the write path against wrapInSplit, refitPanesUnder, createDivider/disposeDivider, findPaneChildren and serializePaneTree, and independently confirmed happy-dom's MutationObserver actually records mutations (so the zero-writes test is real coverage). The tolerance and readSplitRatio formula match serialization, and the recursive plan discards accumulated writes when a deeper subtree mismatches. No reachable input applies a change against a tree that does not match.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

This run re-reviewed the delta since the prior pullfrog review (80a5045): the ratio-read extraction, the new tree-match guards, the apply-path merge, and two new tests.

  • Shared split-ratio read: readSplitRatio and SPLIT_RATIO_TOLERANCE moved into pane-split-ratio.ts; serializePaneTree and the geometry apply now share them with identical near-0.5 behavior (both yield undefined/no-write when total grow is not positive).
  • Refuse zoomed trees: applyPaneLayoutGeometry now returns false with zero DOM contact when either child of a split is display: none — the expand/zoom state, where the expanded pane hides its siblings and owns their flex, so an apply would be overwritten by collapse's saved-style restore.
  • Require exactly one divider: findDividers makes a dividerless or multi-divider split a tree mismatch, so a ratio-only apply never runs against a split whose drag handle is missing or duplicated.
  • Simplified apply path: applyManagedPaneLayoutGeometry folded into applyPaneLayoutGeometry(host, layout) returning boolean; the orientation flip disposes and replaces the divider captured during planning instead of re-querying the DOM.
  • Tests: Added coverage that a zoomed pane tree and a split missing its divider each yield false with no DOM mutations.

I verified the zoom guard against applyExpandedLayoutTo (it sets display: none on every sibling along the path to the root, so the guard trips at the topmost split regardless of which subtree holds the expanded pane), confirmed findDividers/findPaneChildren count direct children only, and ran the suite locally (7 passed).

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@Jinwoo-H
Jinwoo-H merged commit 53b9ccb into main Oct 6, 2026
30 checks passed
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