Skip to content

fix(balance-sizes): preserve total weight instead of resetting to a constant - #2211

Open
MsfPablo wants to merge 1 commit into
nikitabobko:mainfrom
MsfPablo:fix/balance-sizes-resize-command-chaining
Open

fix(balance-sizes): preserve total weight instead of resetting to a constant#2211
MsfPablo wants to merge 1 commit into
nikitabobko:mainfrom
MsfPablo:fix/balance-sizes-resize-command-chaining

Conversation

@MsfPablo

@MsfPablo MsfPablo commented Aug 4, 2026

Copy link
Copy Markdown

Summary

Fixes #1837. balance(_:) assigned a hardcoded weight of 1 to every child, discarding whatever total the container's weights previously summed to.

Weights are only converted to real pixel sizes by the layout pass, which runs once after a whole binding's command list finishes. So when balance-sizes and resize are chained in the same binding, resize's delta calculation still operates against the pre-existing (larger) weight scale of sibling containers, while the just-balanced children were reset to a tiny constant (1) — producing a much wider window than running the same two commands as separate keybind presses.

Fix

Redistribute the container's existing weight total evenly across its children (total / children.count) instead of assigning an arbitrary constant, so later commands in the same list see a consistent scale.

Test plan

  • Updated testBalanceSizes (total 1+2+3=6 → each child becomes 2, not the old hardcoded 1)
  • Added testBalanceSizes_nestedContainerPreservesItsOwnTotal, confirming each nested container's total is redistributed independently
  • Added testBalanceSizesThenResize_behavesLikeResizeAlone, the regression test for the exact chained-command scenario from the issue

I couldn't run the test suite itself in my environment — swift test fails with error: no such module 'XCTest', which I confirmed is pre-existing on a clean main checkout with no changes at all (I only have Xcode Command Line Tools, not a full Xcode install). swift build (the actual app code) compiles cleanly with this change. Happy to have CI confirm the test suite.

…onstant

balance(_:) assigned a hardcoded weight of 1 to every child, discarding
whatever total the container's weights previously summed to. Weights
are only converted to real pixel sizes by the layout pass, which runs
once after a whole binding's command list finishes — so a later command
in the same binding (e.g. resize) still sees the old, larger total via
sibling weights, while the balanced child was reset to a small constant.
Chaining `balance-sizes` then `resize width N` in one keybind therefore
produced a much wider window than running the same two commands as
separate keybind presses.

Redistribute the container's existing weight total evenly across its
children instead of assigning an arbitrary constant, so later commands
in the same list see a consistent scale.

Fixes nikitabobko#1837
@nikitabobko nikitabobko added not-actionable By default, all PRs have this label. If the PR makes sense, the label will be removed. and removed not-actionable By default, all PRs have this label. If the PR makes sense, the label will be removed. labels Aug 10, 2026
@MsfPablo

Copy link
Copy Markdown
Author

Ping on this. The current balance-sizes resets total weight to a constant, which shifts the container's overall size; this preserves it. Happy to walk through the math if useful.

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.

balance-sizes, resize commands don't interact in the expected way when combined together in the config

2 participants