Skip to content

Splitpane drag symmetry - #211

Merged
rorygraves merged 1 commit into
mainfrom
task/splitpane-drag-symmetry
Jun 15, 2026
Merged

Splitpane drag symmetry#211
rorygraves merged 1 commit into
mainfrom
task/splitpane-drag-symmetry

Conversation

@rorygraves

Copy link
Copy Markdown
Contributor

DECISIONS — splitpane-drag-symmetry (fixes #208)

Problem

SplitPane.ratioAt mapped pointer→ratio asymmetrically. With at.x = 1 the
old code computed rel = col - at.x + 1 (range 1..width) and divided by
width, giving a raw ratio range of [1/width, 1]. The far-right edge reached
1.0 but the far-left edge bottomed out at 1/width, never near 0 — a
half-cell bias that broke symmetry about the centre.

Change

modules/termflow-widgets/.../SplitPane.scala, ratioAt:

  • Dropped the +1: rel = col - at.x.value (range 0..width-1).
  • Divided by denom = max(1, span - 1) instead of span.

Result: first/last cells map to exactly 0.0 / 1.0, so the reachable raw
ratio is a symmetric [0, 1] about 0.5 before clampRatio. Applied the same
correction to the Vertical branch (using row/height).

Why width - 1, not just dropping +1

The issue offered "drop the +1 and/or divide by width - 1". Dropping
+1 alone (still /width) yields [0, (width-1)/width] — reaches 0 but not
1, still asymmetric. Only /(width-1) puts both endpoints symmetric, which is
the stated goal. Guarded denom/span-1 with max(1, …) so width == 1
(single-cell region) can't divide by zero.

Tests

  • Updated three existing drag magic-number assertions that encoded the old
    /width mapping (Drag col=1514/19, Release col=54/19, Vertical
    row=87/15). These had to change — they asserted the buggy mapping by
    construction; no symmetric denominator keeps col/width values like 0.75.
  • Added two regressions: (a) for several widths, drags d cells from each end
    produce ratios summing to 1.0 (mirror about 0.5); (b) far-left/far-right
    drags hit the exact raw endpoints 0.0 / 1.0.
  • Layout tests and the sample showcase spec are untouched and green.

Risk

Low. Behaviour change is confined to drag-resize ratio; clampRatio
(MinSizeRatio = 0.05) still bounds the committed ratio, and layout math is
unchanged. The only observable difference is that mid-drag ratios shift
slightly (denominator width-1 vs width) and the divider now reaches both
extremes evenly.

ratioAt biased the pointer->ratio mapping by half a cell (rel = col -
at.x + 1, divided by width), so drags reached ratio 1.0 on the right but
never near 0.0 on the left. Map the first/last cell to 0.0/1.0 by using
rel = col - at.x over a (width-1) denominator, giving a symmetric [0,1]
raw range before clampRatio. Same fix for the Vertical branch.

Update existing drag tests that encoded the old mapping and add a
symmetry regression.
@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@rorygraves
rorygraves merged commit 79b43f2 into main Jun 15, 2026
2 checks passed
@rorygraves
rorygraves deleted the task/splitpane-drag-symmetry branch June 15, 2026 04:12
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.

SplitPane divider drag can't reach the full ratio range (asymmetric)

1 participant